Hi there, I'm having a problem making a players speed equal to a speed leaderstat.
So here i have made a leaderstat for the players speed.
game.Players.PlayerAdded:Connect(function(player)
local stats = Instance.new("Folder")
stats.Name = "leaderstats"
stats.Parent = player
local SpeedValue = Instance.new("IntValue")
SpeedValue.Name = "Speed"
SpeedValue.Value = 2
SpeedValue.Parent = stats
end)
Here i have made it so when a player activates a tool, a remote event is fired (It also has a cooldown script)
local cooldown = false
script.Parent.Activated:Connect(function()
if cooldown == false then
cooldown = true
game.Workspace.MainEvent.AddSpeed:FireServer()
script.Parent.Enabled = false
wait(1.2)
script.Parent.Enabled = true
cooldown = false
end
end)
And here i have made a script inside of the Workspace(with the remote event inside of it named "AddSpeed").
script.AddSpeed.OnServerEvent:Connect(function(player)
player.leaderstats.SpeedValue.Value = player.leaderstats.SpeedValue.Value + 1
end)
This code does work as i can see the speed going up when I activate the tool. The issue i am now having is linking up the speed leaderstat with the players humanoid speed value. I was just wondering if somebody could give me a brief example on how i could do this?

1 comment
You could put in the playeradded function a loop that constantly checks for the value of the Speed. And in the same loop make say something like player.Character.Humanoid.WalkSpeed = player.Character.Humanoid.WalkSpeed +SpeedValue.Value