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

Why this walkspeed script dosen't work?

Hello, devs!

I am begginer dev and I actually don't know how to get Player Humanoid in the script. I wanted to change player walkspeed when he join the game, and then after 20.2 seconds hes walkspeed will change again. I even don't know does it should be normal script or local script and I don't know where is should be located. Thanks in advice.

CODE:

game.Players.PlayerAdded:Connect(function()
	game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 0
	wait(20.2)
	game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 10
end)

2 answers

✓ Accepted answer

The reason it doesn't work is because "LocalPlayer" is only used in Local Scripts. This script will help you out a bit:

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		char.Humanoid.WalkSpeed = 0
		wait(20.2)
		char.Humanoid.WalkSpeed = 10
	end)
end)

I would recommend keeping this a regular script inside of ServerScriptService

This code should be a server script in server script service. However, server scripts cannot find localplayer. To fix this, your code would be:

game.Players.PlayerAdded:Connect(function(player)
    player.Character.Humanoid.WalkSpeed = 0
    wait(20.2)
    player.Character.Humanoid.WalkSpeed = 10
end)

I think this code is self-explanatory, but if it isn't, please tell me.

1 comment

0

Oh, rip I forgot the other function :(

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