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

Speed and HighestSpeed not changing (leaderstats)?

I have been trying to make the characters speed and highest ever speed show on leaderstats but I cannot get it to work:

game.Players.PlayerAdded:Connect(function(player)
	local character = player.Character

	local leaderstats = Instance.new("BoolValue",player)
	leaderstats.Name = "leaderstats"
	
	local Speed = Instance.new("IntValue", leaderstats)
	Speed.Name = "Speed"	
	
	local HighestSpeed = Instance.new("IntValue", leaderstats)
	HighestSpeed.Name = "HighestSpeed"
	
	Speed.Value = 0
	HighestSpeed.Value = 0
	
	while true do--this is where it could stop working
		task.wait()--or maybe here
		Speed.Value = character.Humanoid.WalkSpeed--probably here 
		if Speed.Value > HighestSpeed.Value then
			HighestSpeed.Value = Speed.Value
		end
	end
end)

The while true do loop does not run

If anyone has a solution I would love the help!

5 comments

0

On line 18, you just typed; Speed.Value = Character.Humanoid.Walkspeed. You did not define the player in a variable nor the character. On the very top of you script, try making a variable that defines the player, and a variable that defines the character.

0

I dont know if this is the problem, but try it.

0

that isn't the problem. He might not be using the output so really they need to put character:WaitForChild('Humanoid') since it is playeradded and not characteradded

0

That didn't work greatniel80

0

In that case you are using a localscript, use a regular script and parent it to workspace instead. The PlayerAdded wasn't working to begin with since it is a localscript, I probably should've mentioned this earlier

1 answer

Try this?

Script:

game.Players.PlayerAdded:Connect(function(player)
        player.CharacterAdded:Connect(function(character)
            local leaderstats = Instance.new("BoolValue", player)
            leaderstats.Name = "leaderstats"

            local Speed = Instance.new("IntValue", leaderstats)
            Speed.Name = "Speed"

            local HighestSpeed = Instance.new("IntValue", leaderstats)
                HighestSpeed.Name = "HighestSpeed"

            Speed.Value = 0
            HighestSpeed.Value = 0

            while wait() do
                    Speed.Value = character.Humanoid.WalkSpeed
                    if Speed.Value > HighestSpeed.Value then
                        HighestSpeed.Value = Speed.Value
                    end
                end
            end
        )
    end
)

2 comments

0

Ok I'll try it!

0

Sadly It didn't work :(

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