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

How can I change the player's speed when they spawn?

I want to make a game that involves running all the time. I think it has something to do with this:

game.Workspace.Player.Humanoid.Running:connect(function(speed)
    if speed > 0 then
        print("Player is running")
    else
        print("Player has stopped")
    end
end)

Although I'm not sure.

Thanks!

1 answer

The Humanoid.Running event that you refer to fires when the Humanoid starts or stops running, not when the Player spawns.

If you want to adjust the speed of each player when they spawn from a LocalScript, all you'd need to do is this:

repeat wait() until game.Players.LocalPlayer
player = game.Players.LocalPlayer

repeat wait() until player.Character
character = player.Character

repeat wait() until character:FindFirstChild("Humanoid")
humanoid = character.Humanoid

humanoid.WalkSpeed = 25 --Set the speed that you want them to have

The important thing to bear in mind when writing behaviour that should initiate when a Player spawns is to wait for the Player's Character and Humanoid before trying to modify them.

If you wanted to adjust the WalkSpeed of each Player using a global Script, you would subscribe to the PlayerAdded event of the Players GameService, and then for each Player reference that you get subscribe to the CharacterAdded event:

game.Players.PlayerAdded:connect(function(player)
	player.CharacterAdded:connect(function(character)
		while not character:FindFirstChild("Humanoid") do wait() end
		character.Humanoid.WalkSpeed = 25 --Set the speed
	end)
end)

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