Ok so in the Roblox tutorials for scripting for some reason I’m just kinda confused about lines 3-5.
This is the video:
https://www.youtube.com/watch?v=8ejtpQAYfpk (at time code 12:46 you can see the script)
Ok so in the Roblox tutorials for scripting for some reason I’m just kinda confused about lines 3-5.
This is the video:
https://www.youtube.com/watch?v=8ejtpQAYfpk (at time code 12:46 you can see the script)
It changes the walkspeed of the humanoid essentitally differenting how fast or slow the player is moving at.
They find the humanoid via a Touched event by which grabs the character from the hit using part, an argument.
However, if you plan not to use the same function on different parts and just for one particular part, you can do:
local speedboost = script.Parent
speedBoost.Touched:Connect(function(part)
-- etc code
end)
Exactly the same thing.
If you want to perform code on a multitude of parts without having to declare a variable to each individual part, you can utilize module scripts or collection service which allows you to tag objects and then apply a function/event to them, you can use the tutorial here (lol):
The argument being passed to the function steppedOn
is automatically passed by Roblox’s engine.
When you connect a function to a signal via :Connect
then special parameters are passed to the function you passed to the :Connect
method which are dependent on the signal you’re connecting a function to.
In this case Roblox’s engine passes the part that hit the speedBoost
part.
I suggest reading the API documentation for a more “elaborated” response.
https://developer.roblox.com/en-us/api-reference/event/BasePart/Touched
function SteppedOn will check if the part’s parent is a character, then give the speed boost.
This function will be connected when player’s character steps on the part
I should also clarify other things:
Variable names do not have to be the same as a part, infact they can be anything.
local epic = workspace.CoolPart
In this case the part
variable is defined by Roblox’s engine (see my first reply)