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!
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)
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)