Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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!

1 comment

0

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

2 answers

✓ Accepted answer

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)

3 comments

0

this doesn't check if hit is a player.

0

it works thanks!

0

again, this isn't the correct answer... trying touching it with something other than a part of a player

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)

3 comments

0

You don't need the "if character and", just "if character:FindFirstChild("Humanoid") then"

0

thanks both work

0

That line didn't need to be extended...but yes

This discussion is preserved as it was. New answers, comments, and votes are closed.