I am making a script that tracks the player’s current speed and shows it on the leaderboard, but the player’s actual speed and the leaderboard value don’t change, and I don’t know why.
Character.Humanoid.Running:Connect(function()
while true do
wait(1)
WalkSpeed = WalkSpeed + 1
localplr.leaderstats.Speed.Value = localplr.CharacterWalkSpeed
end
end)
There isn’t enough information provided in this thread so it’s relatively hard to determine what your problem is. I’m going to make a few assumptions based on the code you’ve already provided.
The first thing is addressing your use of a while loop: don’t create a non-terminating while loop. What you should do instead is add a condition that checks whether the humanoid is still moving or not. Whenever Running fires, it spawns up a new non-terminating while loop.
The second thing is where the script is coming from. If you’re attempting to make this change from a LocalScript, you’ll have no dice in the change showing up to other players so you won’t be able to make a leaderboard for steps. I encourage you to look towards RemoteEvents for accomplishing this.
Aside from that, it’d be appreciated if you provided more of your code and possibly hierarchy shots so you can be further helped.
Here’s a quick script I wrote up to basically mimic what you’ve made, but better.
Oh yeah, I also got rid of CharacterWalkSpeed (because i don’t know what it is)
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local Leaderstats = Player:WaitForChild("Leaderstats")
local Speed = Leaderstats:WaitForChild("Speed")
local Running = false
Humanoid.Running:Connect(function(Speed)
if Speed > .1 then
Running = true
else
Running = false
end
end)
while wait(1) do
if Running then
Humanoid.WalkSpeed = Humanoid.WalkSpeed + 1
Speed.Value = Humanoid.WalkSpeed
end
end
You should most likely run this inside of a server script, as localscripts are… well… local.