I need to know if the following script would work correctly, if it will or I did something wrong, please leave feedback in the form of an answer, please.
Click > Walkspeed 100 Click Again > Walkspeed 15
01 | local Player = game.Players.LocalPlayer |
02 | local Humanoid = Player.Character.Humanoid |
03 |
04 | function onClick() |
05 | Humanoid.Walkspeed = 100 |
06 | if Humanoid.Walkspeed = = 100 then |
07 | Humanoid.Walkspeed = 15 |
08 | else |
09 | Humanoid.Walkspeed 100 |
10 | end |
11 | script.Parent.MouseButton 1 Click:connect(onClick) |
local Player = game.Players.LocalPlayer
local Humanoid = Player.Character.Humanoid
function onClick()
Humanoid.Walkspeed = 100
if Humanoid.Walkspeed == 100 then Humanoid.Walkspeed = 15
else
1 | Humanoid.Walkspeed 100 |
end
script.Parent.MouseButton1Click:connect(onClick)
Indenting affects the order in which code runs. So I'd suggest indenting the if and else statements.
1 | local Player = game.Players.LocalPlayer |
2 | local Hum = Player.Character:WaitForChild( "Humanoid" ) |
3 | script.Parent.MouseButton 1 Click:connect( function () |
4 | if Hum.Walkspeed > = 100 then |
5 | Hum.Walkspeed = 15 |
6 | else |
7 | Hum.Walkspeed = 100 |
8 | end |
9 | end ) |
Put this script in a textbutton inside a screen gui or where ever. Boom.
01 | local player = game.Players.LocalPlayer |
02 |
03 |
04 | function whenClicked() |
05 | if player.Character.Humanoid.WalkSpeed = = 16 then |
06 | player.Character.Humanoid.WalkSpeed = 100 |
07 | else if player.Character.Humanoid.WalkSpeed = = 100 then |
08 | player.Character.Humanoid.WalkSpeed = 16 |
09 | end |
10 | end |
11 | end |
12 |
13 | script.Parent.MouseButton 1 Click:connect(whenClicked) |
This has been tested and works.