Hello!
I am trying to set the humanoids walkspeed to an IntValue in a leaderstats script.
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = player:FindFirstChild("leaderstats")
if not leaderstats then
leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
end
local timePlayed = leaderstats:FindFirstChild("TimePlayed")
if not timePlayed then
timePlayed = Instance.new("IntValue") -- different Int value, not related
timePlayed.Name = "Speed"
timePlayed.Value = 0
timePlayed.Parent = leaderstats
end
task.spawn(function()
while true do
task.wait(1)
timePlayed.Value = timePlayed.Value + 1 -- Using this for something else
script.Value.Value = timePlayed.Value --This is the value I'm using
end
end)
Every second the first value increases by 1 as intended. I need the 2nd value to copy the first value’s value. I want the second value to be the characters walkspeed.
I have a script in serverscriptservice to set the player speed to value2
function addSpeed(hum)
spawn(function()
while wait(1) do
hum.WalkSpeed = game.Workspace.leaderstats.Value2.Value/4 -- HERE
print("The value is:", game.Workspace.leaderstats.Value2.Value) -- Prints 0
end
end)
end
--not part of issue
game.Players.PlayerAdded:Connect(function(player)
local walkspeed
player.CharacterAdded:Connect(function(char)
local humanoid = char:WaitForChild("Humanoid")
if walkspeed then
wait(0.5)
humanoid.WalkSpeed = walkspeed
end
addSpeed(humanoid)
humanoid.Died:Connect(function()
walkspeed = humanoid.WalkSpeed
wait(1)
end)
end)
end)
Additionally, I have a local script in StarterGui to update the second value to the first.
task.spawn(function()
while true do
game.Workspace.leaderstats.Value2.Value = game.Workspace.leaderstats.Value.Value
wait(0.1)
print("script running")
end
end)
(I need to have two values for something later)
When I run the game, both values increase as intended, but for some the reason the script thinks that the second value is 0. (Top of 2nd script)
If I change
hum.WalkSpeed = game.Workspace.leaderstats.Value2.Value/4 -- HERE
to the first value, it works fine. But I need it to be value 2. I don’t know why it works for Value 1 and not Value 2.
I’ve been stuck on this for many hours now.
All help is appreciated!