Nonono, you're setting two values to each other! Basically you're saying:
When you create a variable, the first part needs to be the name. The correct way to do this would be:
'Chant' is the name of variable, and you're assigning that variable to the script's parent, which is a part called Chant.
Now the next part...
When the script sees this it thinks, "When "Chant is touched, do nothing". The problem here is that you aren't telling it what to do and where to do it. Instead, when 'Chant' is touched, you should connect it to a function like this:
1 | Chant.Touched:Connect( function () |
Now whatever is in between the function will run when 'Chant' is touched!
When you use .Touched
, the part that touches it is passed as the argument in the parameter of the function. Basically that means you can find out what part touches 'Chant'. By doing this we can check if the part that touched 'Chant' is a humanoid, then if it is, we can change it's speed.
1 | Chant.Touched:Connect( function (otherPart) |
Now what you put was:
Of course that didn't do anything! You just created a variable named "PlayerSpeed" and then assigned it 50. You didnt' change anything about the player who touched it. Now that we have access to the thing that touched it though, we can change the player's walkspeed.
Let's say your arm touches the part. We don't want to change your arm's walkspeed right? So we would say:
1 | Chant.Touched:Connect( function (otherPart) |
2 | local character = otherPart.Parent |
3 | local humanoid = character:FindFirstChild( "Humanoid" ) |
This basically says, "If a part touches 'Chant', run this function: the parent of the part that touched it is called character. Let's search the character and see if we can find a "Humanoid".
Now we can check if the Humanoid has been found. If it has then we know it's a player and then we can change the player's WalkSpeed.
1 | Chant.Touched:Connect( function (otherPart) |
2 | local character = otherPart.Parent |
3 | local humanoid = character:FindFirstChild( "Humanoid" ) |
5 | humanoid.WalkSpeed = 50 |
You can see we checked if humanoid then
to see if the part that touched 'Chant' was a human.
WalkSpeed
is a property of a humanoid, that's how we're able to change it. Now if you test this out it should turn your walkspeed to 50 if you touch it.
It might be confusing at first, but make sure to practice, you'll get better that way. Here's the end product with comments.
1 | local Chant = script.Parent |
3 | Chant.Touched:Connect( function (otherPart) |
4 | local character = otherPart.Parent |
5 | local humanoid = character:FindFirstChild( "Humanoid" ) |
7 | humanoid.WalkSpeed = 50 |
It's a little messy, but I hope you got at least something out of it. :)