I have a ButtonGui and when I click it a textlabel counts up by 1's every click. When I click the button 1 time, the walkspeed changes to 1 but if you click it 20 times, walkspeed does not change :(
Plr = game.Players.LocalPlayer I = Instance.new("IntValue") I.Parent = Plr TextL = Plr.PlayerGui.Clicker.TextLabel Plr.Character.Humanoid.WalkSpeed = 0 I.Changed:connect(function() TextL.Text = "Clicks: " ..I.Value end) script.Parent.MouseButton1Click:connect(function() I.Value = I.Value + 1 end) --Problem is below. while wait(.1) do if I.Value == 1 then Plr.Character.Humanoid.WalkSpeed = 1 end end while wait(.1) do if I.Value == 20 then Plr.Character.Humanoid.WalkSpeed = 20 end end
The second while loop never starts because the first never stops and therefore it never checks if the value is 20. You could either use one while loop and elseif or just check the value after you update it.
while wait(.1) do if I.Value == 1 then Plr.Character.Humanoid.WalkSpeed = 1 elseif I.Value == 20 then Plr.Character.Humanoid.WalkSpeed = 20 end end
Or
script.Parent.MouseButton1Click:connect(function() I.Value = I.Value + 1 if I.Value == 1 then Plr.Character.Humanoid.WalkSpeed = 1 elseif I.Value == 20 then Plr.Character.Humanoid.WalkSpeed = 20 end end)
You also could use the Changed event.
You do not need to create an IntValue for your walkspeed, because you can get the walkspeed directly off the humanoid.
The problem is your code is written so that it changes ONLY on 1 and 20. Not any of the values in between.
I changed it so that on click, the code changes your walkspeed and your textlabel spontaneously.
local Plr = game.Players.LocalPlayer local TextL = Plr.PlayerGui.Clicker.TextLabel Plr.Character.Humanoid.WalkSpeed = 0 script.Parent.MouseButton1Click:connect(function() Plr.Character.Humanoid.WalkSpeed = Plr.Character.Humanoid.WalkSpeed + 1 TextL.Text = "Clicks: " ..Plr.Character.Humanoid.WalkSpeed end)