I’m trying to increase the walkspeed of a player every second. The speed increases, however I set up a leaderstats value that will display their speed value, but it doesn’t change…
Script in ServerScriptService
--[[ LEADERSTATS ]]--
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local speed = Instance.new("IntValue")
speed.Name = "Speed"
speed.Parent = leaderstats
--[[ SPEED CHANGE ]]--
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character.Humanoid
local add = 1
while true do
wait(1)
humanoid.WalkSpeed += add
end
humanoid:GetPropertyChangedSignal("WalkSpeed"):Connect(function(newSpeed)
speed.Value = newSpeed
end)
end)
--[[ LEADERSTATS ]]--
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local speed = Instance.new("IntValue")
speed.Name = "Speed"
speed.Parent = leaderstats
--[[ SPEED CHANGE ]]--
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character.Humanoid
local add = 1
while true do
wait(1)
humanoid.WalkSpeed += add
speed.Value = humanoid.WalkSpeed
end
end)
I think the problem maybe was because the function just activated when walkspeed was already changed, so it wouldn’t work, and I think that if you change the value same time you change the walkspeed, it would be a smaller script, even if it’s only 2 lines of difference.