Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why isn't my brick increasing the character's movement speed?

Asked by 5 years ago

I'm trying to learn how to script and I'm starting off with trying to increase the characters movement speed when it touches a brick but it's not working?

local brick = script.parent

script.Parent.Touched:connect(function(hit)
    local character = hit.Parent
    character.WalkSpeed = 50
end)

Thanks for any help!

0
You have to make sure hit is actually a character by inserting: if character:("Humanoid") then between lines 4 and 5 thebayou 441 — 5y

2 answers

Log in to vote
1
Answered by 5 years ago

The issue you are having is very simple. You have to change the walkspeed of the character by using the humanoid, instead of just the character. I would also suggest checking that the character exists so the script doesn't break.

local brick = script.Parent

script.Parent.Touched:Connect(function(hit) -- connect is deprecated
    local character = hit.Parent
    if character then
        character:FindFirstChild('Humanoid').WalkSpeed = 50 -- find humanoid
    end
end)
0
this doesn't check if hit is a player. thebayou 441 — 5y
0
it works thanks! 2052Game 25 — 5y
0
again, this isn't the correct answer... trying touching it with something other than a part of a player thebayou 441 — 5y
Ad
Log in to vote
1
Answered by
thebayou 441 Moderation Voter
5 years ago
Edited 5 years ago

Mythical's answer isn't actually completely correct. While he is right to say that you need to apply the WalkSpeed change to the character's Humanoid and not the character itself, you also first need to make sure that hit really is a player.

local brick = script.Parent

script.Parent.Touched:Connect(function(hit) -- connect is deprecated
    local character = hit.Parent
    if character and character:FindFirstChild("Humanoid") then
        character:FindFirstChild('Humanoid').WalkSpeed = 50 -- find humanoid
    end
end)
0
You don't need the "if character and", just "if character:FindFirstChild("Humanoid") then" User#19524 175 — 5y
0
thanks both work 2052Game 25 — 5y
0
That line didn't need to be extended...but yes User#19524 175 — 5y

Answer this question