Change leaderstats based on player's speed/jumppower

game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Char)
		while true do
			task.wait(2)
			Player.leaderstats.Speed.Value = Char.Humanoid.WalkSpeed
			Player.leaderstats.JumpPower.Value = Char.Humanoid.JumpPower
		end
	end)
end)

Hey there, I want the leaderstats to display the player’s walkspeed and jumppower. However, it doesn’t update.

4 Likes

Would it not be more efficient to use :GetPropertyChangedSignal and in general better then doing a while true loop?

@Lostude
This is what i came up with:

Server Script / ServerScriptService:

local Players  = game.Players

Players.PlayerAdded:Connect(function(Player)
	local leaderstats = Instance.new("Folder", Player)
	leaderstats.Name = "leaderstats"
	
	local WalkSpeed = Instance.new("IntValue", leaderstats)
	WalkSpeed.Name = "WalkSpeed"
	
	local JumpPower = Instance.new("IntValue", leaderstats)
	JumpPower.Name = "JumpPower"
		
	Player.CharacterAdded:Connect(function(Char)
		local Humanoid = Char:FindFirstChild("Humanoid")	
		WalkSpeed.Value = Humanoid.WalkSpeed
		JumpPower.Value = Humanoid.JumpPower or Humanoid.JumpHeight
		
		
	end)
		
end)

Edit: I looked and noticed you were talking about Saving.

Here is a LocalScript so the stats constantly update for the Player:
StarterCharacterScripts:

local Char = script.Parent
local Hum = Char:FindFirstChild("Humanoid")

local ls = game.Players.LocalPlayer:WaitForChild("leaderstats")
while wait() do
	ls.WalkSpeed.Value = Hum.WalkSpeed
	ls.JumpPower.Value = Hum.JumpPower or Hum.Jumpheight
end

3 Likes

Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder", Player)
	leaderstats.Name = "leaderstats"
	
	local walkstat = Instance.new("IntValue", leaderstats)
	WalkSpeed.Name = "WalkSpeed"
	
	local jumpstat = Instance.new("IntValue", leaderstats)
	JumpPower.Name = "JumpPower"
		
	player.CharacterAdded:Connect(function(Character)

walkstat.Value = Character.humanoid.WalkSpeed

jumpstat.Value = Character.humanoid.JumpPower
		
         Character.humanoid:GetPropertyChangedSignal(“WalkSpeed”):Connect(function()
		walkstat.Value = Character.humanoid.WalkSpeed
		end)

Character.humanoid:GetPropertyChangedSignal(“JumpPower”):Connect(function()
        jumpstat.Value = Character.humanoid.JumpPower
end)
		
end)

I tested the script, it doesn’t appear to Update the Values. There is also some grammar errors inside your script.

1 Like

Try this:

-- services
local players = game:GetService("Players")

-- variables

-- functions
players.PlayerAdded:Connect(function(player: Player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	
	local walkSpeed = Instance.new("NumberValue")
	walkSpeed.Name = "WalkSpeed"
	walkSpeed.Parent = leaderstats
	
	local jumpForce = Instance.new("NumberValue")
	jumpForce.Name = "JumpForce"
	jumpForce.Parent = leaderstats
	
	leaderstats.Parent = player
	
	player.CharacterAdded:Connect(function(character: Model)
		local humanoid = character:WaitForChild("Humanoid")
		
		humanoid:GetPropertyChangedSignal("WalkSpeed"):Connect(function()
			walkSpeed.Value = humanoid.WalkSpeed
		end)
		
		humanoid:GetPropertyChangedSignal("JumpHeight"):Connect(function()
			jumpForce.Value = humanoid.JumpHeight
		end)
		
		walkSpeed.Value = humanoid.WalkSpeed
		jumpForce.Value = humanoid.JumpHeight
	end)
end)

Also make sure that you change the walk speed/jump height from the server and not the client, since the server doesn’t recognize changes from the client.

I tried that as well, did many tests and workarounds, doesnt work either. Even after improving it, it didnt work. I have an idea ill try but i do not have the time right now so ill do it later

It worked perfectly for me. Are you changing the humanoid’s walk speed/jump force from a LocalScript?, if you are it wont work because you are changing it from the client and not the actual server.

Do the values show up tho?

Also where are my grammatical mistakes (I typed it on my phone :skull:)

im doing it from the server script service, i tested it before, didnt work.

also i clearly said:

@Inpultion
After Testing with your script, I checked it again and yes, it does work, but this works as well:

local Players  = game.Players

Players.PlayerAdded:Connect(function(Player)
	local leaderstats = Instance.new("Folder", Player)
	leaderstats.Name = "leaderstats"
	
	local WalkSpeed = Instance.new("IntValue", leaderstats)
	WalkSpeed.Name = "WalkSpeed"
	
	local JumpPower = Instance.new("IntValue", leaderstats)
	JumpPower.Name = "JumpPower"
		
	Player.CharacterAdded:Connect(function(Char)
		local Humanoid = Char:FindFirstChild("Humanoid")	
		
		WalkSpeed.Value = Humanoid.WalkSpeed
		JumpPower.Value = Humanoid.JumpPower
		
while wait() do
		WalkSpeed.Value = Humanoid.WalkSpeed
			JumpPower.Value = Humanoid.JumpHeight
	end
	end)
		
end)

It doesn’t update update peoples leaderstats all a once, just the LocalPlayer, the changes appears on both clients and only applies it to one person, i was on the right track with my other posts but i used the client instead of the server.

My Script (Player1):


My Script (Player2):

Here you can find 2 of them with the Strings. They are not Strings according to the script and on Studio.

1 Like

I’m getting a little confused about what you’re not trying to achieve. Are you trying to give each player their own leaderstat, and have the values changed within (walk speed/jump force) be the player’s own walk speed/jump force. Or are you trying to get all the players leaderstats to be the same as one specific player? I assume it’s the first one but I tested it on a 2 client and 1 server test. It worked just as intended. I Changed player 1’s humanoid jump force and got the expected result of both clients seeing the same value on their ‘individual screens’. Then I changed player 2’s humanoid walk speed and I got the same result, everything worked as intended (If we’re both looking at the same desire).

c1: client 1
c2: client 2
s: server

Red arrows indicate where the values were manually changed.

Edit: replied to the wrong person, supposed to be op.

Sorry for the late reply, but this worked, thank you!

I’m using DevForum on mobile and don’t have access to studio sometimes, so sorry for any errors in my scripts

now how to datastore humanoid speed