Reputation: 11
I'm trying to make a one piece game on Roblox but I don't know much about coding and so when I tried a script that I got off YouTube it wouldn't work right(the guy was making a fireball). Could someone help me out with that?
Upvotes: 1
Views: 1202
Reputation: 85
Technically any kind of script will work, but ideally you'll want to use a combination of a LocalScript, a normal Script, and a RemoteEvent.
The explanations below are fairly basic.
A LocalScript
is a script that only runs on a client. A LocalScript is capable of executing almost any task you can complete using any other script in Roblox, but typically only the client that the LocalScript is running on will be affected.
For example, if you tried changing the color of a blue brick to red, then the client that the LocalScript is running on will see a red brick but everyone else will still see blue because LocalScripts cannot affect anything beyond the client the LocalScript is being run on without some help from a RemoteEvent (I'll touch on that later).
A Script
is a script that runs on the server. You can use it to make server-side changes that will be replicated across all clients. For example, if you wanted to change our blue brick from earlier to red in a Script instead of a LocalScript, then everyone will see a red brick because changes on the server are displayed across all clients.
A RemoteEvent
is a special object that you can use for Scripts and LocalScripts to communicate. This allows you to have a client running some LocalScript to request some action that will be carried about by the Script.
For example, if you made a GUI with a button that let you change the blue brick into a red brick by clicking a button in the GUI, then you could have (1) a LocalScript detect when the button is clicked, (2) have the LocalScript "fire" an event through the RemoteEvent, and (3) have a Script on the server "listening" for an event to be fired through the RemoteEvent, and when it hears one, it'll change the blue brick into a red one. That way, you can have some client-only object (in this case, the button) influence something on the server.
For more information, check out the Roblox Developer wiki! It is perhaps the #1 resource for all things Roblox. Here you can find plenty of tutorials as well as the documentation for everything in Roblox. You could start by looking up basic coding tutorials to help yourself understand how Lua and programming in general works, or you could look up articles about LocalScripts, Scripts, and RemoteEvents.
If I were you, I would have a Tool that has a LocalScript inside of it. In the LocalScript, you could have it listen for whenever the player clicks, which would work like so:
-- LocalScript code
local tool = script.Parent -- Gets the tool object that this LocalScript belongs inside
local remote = game:GetService("ReplicatedStorage"):WaitForChild("FireballTool") -- Put a RemoteEvent object inside ReplicatedStorage and name it FireballTool (case sensitive!)
tool.Equipped:connect(function(mouse) -- This runs the code nested inside of it any time the tool is equipped
mouse.Button1Down:connect(function() -- This runs the code nested inside any time the player clicks
remote:FireServer()
end)
end)
And then make a Script inside ServerScriptService that looks like this:
-- Server Script code
local remote = game:GetService("ReplicatedStorage"):WaitForChild("FireballTool")
remote.OnClientEvent:connect(function(player)
local fireball = Instance.new("Part") -- Spawns in a new Part (a brick)
fireball.CFrame = player.Character.Torso.CFrame -- This will teleport the brick into the player's character's torso, assuming you're using the R6 body type. This is mainly so the fireball starts in the right place.
-- Put code here to define the fireball, i.e. maybe you want to make it invisible and put flames on it or something
fireball.Parent = workspace -- Instance.new("Part") only creates a new Part; it doesn't put it in Workspace by default and therefore will be basically nonexistent to all the players. This will move the Part into Workspace, which makes it visible.
-- Put code here to make the fireball move. You could probably just use a rocket launcher script or something as a reference.
end)
Remember, check the Roblox developer wiki! If you're confused about anything here, go search it up in the developer wiki. It will definitely provide a way better and more in-depth explanation about what the heck is going on here.
I hope this helps you get on the right track, though. Good luck to you on your game!
Upvotes: 3