Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Why isn't this leaderstat speed changer working?

Asked by
6zk8 95
4 years ago

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.

1
Make sure your script isn't actuallly instantly failing. In general an infinite while loop without a wait inside will almost instantly break. User#834 0 — 4y
0
I know, I just forgot 6zk8 95 — 4y
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. SethHeinzman 284 — 4y
0
If you can that’s bad practice lol. SethHeinzman 284 — 4y
View all comments (2 more)
0
Just use a ServerScript with "game.Players.PlayerAdded". youtubemasterWOW 2741 — 4y
0
Is the local 11 a number? If so, changed that to something not a number. XviperIink 428 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

Please provide explanation with your answers. Simply posting code does not spread knowledge of integral scripting processes which helps people understand the logic and reasoning behind your 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.

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. youtubemasterWOW 2741 — 4y
Ad

Answer this question