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

How do I make a leaderstat be a player's walkspeed?

Here is where I defined player:

game.Players.PlayerAdded:connect(function(player)

This is my script to create the leaderstat:

	local speed = Instance.new("IntValue")
	speed.Value = walkspeed
	speed.Parent = leaderStats
	speed.Name = "Speed"

I just want to make a variable called walkspeed now but how do I make it equal the player's walkspeed?

2 comments

0

speed.Value = player.Character.Humanoid.WalkSpeed

0

do like humanoid.WalkSpeed = speed.Value

1 answer


local speed = Instance.new("IntValue")
speed.Value = player.Character.Humanoid.WalkSpeed
speed.Parent = leaderStats
speed.Name = "Speed"

8 comments

0

13:36:57.858 - Workspace.Main:79: attempt to index field 'Character' (a nil value)

0

Try speed.Value = player:WaitForChild("Character").Humanoid.WalkSpeed

0

No error shows up but it won't work

0

If character is nil, this can failure

0

character might have not loaded yet, repeat wait() until player.Character should fix this

0

repeat wait until character is not a good way

0

then what is the best way to do this?

0

player.CharacterAdded:Wait() or player.CharacterAdded:Connect(function() ... end) the CharacterAdded:Wait() only works 1 attempt

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