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 show a Humanoids speed on Leaderboards?

When I was typing I thought it was completely simple, but when I looked at it as I got the error I just couldn't figure out. I just thought I would put Speed.Value as game.Players.LocalPlayers.Character.Humanoid.WalkSpeed. Any way this is what I had.

game.Players.PlayerAdded:Connect(function(player)
	
	
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player
	
	local plr = game.Players.LocalPlayer.Character.Humanoid
	local speed = Instance.new("NumberValue")
	speed.Name = "Speed"
	speed.Parent = leaderstats
	speed.Value =  plr.WalkSpeed
	 
	
	
end)

3 answers

Instead of checking for the walkspeed in the player you want to check the humanoids walkspeed. Use player.Character.Humanoid.WalkSpeed to start it off then in another script that you put inside the players character (By placing it in game.StarterPlayer.StarterCharacterScripts) with this code:

while wait() do
	local Char = script.Parent
	local Humanoid = Char:WaitForChild("Humanoid")
	local player = game.Players:GetPlayerFromCharacter(Char)
	
	if player then --Just to make sure
		local stats = player:WaitForChild("leaderstats")
		local speed = stats:WaitForChild("Speed")
		speed.Value = Humanoid.WalkSpeed
	end
end

Remember to put that in a server script not a local script

9 comments

0

What are you saying I should do with the player.Character.Humanoid.WalkSpeed?

0

I would recommend using :GetPropertyChangelSignal() to do this.

0

And don't you need to express humanoid by doing game.Player etc.

0

Not if you already have the player expressed

0

in your leaderboard use the player.Character.Humanoid.WalkSpeed to set it by default

0

Where would I put player.Character.Humanoid.WalkSpeed

0

nvm

0

Its saying Humanoid is a (nil value)

0

infact have the leaderstat script set it to 16 be default

Could you do... (LeaderStats is your script)

speed.Value = game:FindFirstChild("LeaderStats")

1 comment

0

Nope

Well in this case follow these steps.

  1. Make sure that your leaderstats script only has the variables such as speed. As I see up there you have used LocalPlayer which wont work in normal scripts.

  2. Just delete those and make a normal leaderstats script with speed or the things you want.

  3. Insert a local script in starter player > starter character scripts.

  4. In that local script type in the following.

while wait(1) do
	local plr = game.Players.LocalPlayer
	local speed = plr.leaderstats.Speed
	speed.Value = script.Parent:FindFirstChild("Humanoid").WalkSpeed
end

OR if you want to make the opposite. (Leaderstats = character speed) then follow this code


while wait(1) do
	local plr = game.Players.LocalPlayer
	local speed = plr.leaderstats.Speed
	script.Parent:FindFirstChild("Humanoid").WalkSpeed = speed.Value
end

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