local StarterCharacter = game.StarterPlayer
function Test(part)
StarterCharacter.CharacterWalkSpeed = 0
wait(5)
StarterCharacter.CharacterWalkSpeed = 16
end
end
Test()
I know the mistake is that for starterPlayer its adjusting the speed but you’ll need to reset to get it. Im trying to make this code run when the player joins the game. any other fixes to this?
Yes, as you mentioned, this won’t immediately work because you’re changing attributes of StarterPlayer at runtime. If you want your walkspeed to change at runtime, you need to modify the walkspeed attribute of the player’s humanoid.
To run when the player connects to the game, you’ll want to include
game.Players.PlayerAdded:Connect(function(player)
--your code here
end)
Whichever Instance triggered the PlayerAdded event will be passed through the function as the player parameter. In this case, all of the instances will be Player instances (not to be mistaken with an avatar model).
Then, to modify the walkspeed attribute, you’ll want to find the player’s avatar in the workspace, then modify the walkspeed attribute of that avatar’s humanoid. However, do note that you’ll want to make sure the player’s avatar exists first, otherwise your script will break.
if player.Character == nil then game.Workspace:WaitForChild(player.Name) end --check that the avatar has been loaded into the workspace
player.Character.Humanoid.WalkSpeed = 0 --access the avatar's humanoid and set the walkspeed to the desired value
Also, do note that player in the above code example is referring to the player parameter of the first code example.
so uh u did startercharacter = game.starterplayer but this wont work ofc cuz no such thing as a starterplayer. if u on a local script do game.players.localplayer to get the player. instead of doing StarterCharacter.CharacterWalkSpeed do StarterCharacter.Character.Humanoid.WalkSpeed = 0 assuming your startercharacter is a player instead of player