Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why isn't this leaderstat speed changer working?

In a local script:

game.Players.LocalPlayer.CharacterAdded:Connect(function()
local ll = game.Players.LocalPlayer.leaderstats.Sugar.Value
while true do
  game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = tonumber(ll / 20)
  game.Players.LocalPlayer.Character.Humanoid.JumpPower = tonumber(ll / 20)
end
end)

It is meant to change the jump power and walk speed to the Sugar leaderstats divided by 10.

Thanks.

6 comments

1

Make sure your script isn't actuallly instantly failing. In general an infinite while loop without a wait inside will almost instantly break.

0

I know, I just forgot

1

Any changes made to a value in a localscript will not change on the server. So other players wouldn’t see you waking or jumping faster or higher. Change 11 to a word. I don’t think you can name variables numbers without having a letter before it.

0

If you can that’s bad practice lol.

0

Just use a ServerScript with "game.Players.PlayerAdded".

0

Is the local 11 a number? If so, changed that to something not a number.

1 answer

You'll want to revise your script into this:

game.Players.PlayerAdded:Connect(function()plr)
     local ll = plr:WaitForChild("leaderstats").Sugar.Value
     plr.CharacterAdded:Connect(function(char)
          while wait() do
               local human = char:WaitForChild("Humanoid")
               human.WalkSpeed = tonumber(ll / 20) -- You said that the value should be Sugar divided by 10, so these 20 should be 10s (unless that was a typo)
               human.JumpPower = tonumber(ll / 20)
          end
     end)
end)

Make sure that the script is a gobal script and not local.

This script will run when a player joins your game. When the character loads in, the script will begin to look for the character's humanoid. Replacing while true do with while wait() do will stop you game from crashing. If you wanted to set the walkspeed and jumppower to Sugar didvided by 10, you'd set the 20's in the script to 10's.

1 comment

0

Instead of a while true do loop use a "while character do" loop as while true do loops will not let the script execute code outside of the loop. A "while character do" will break/stop whenever the character is destroyed.

This discussion is preserved as it was. New answers, comments, and votes are closed.