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

Hello, Would this script work correctly?

Asked by 8 years ago
Edited 8 years ago

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

01local Player = game.Players.LocalPlayer
02local Humanoid = Player.Character.Humanoid
03 
04function onClick()
05Humanoid.Walkspeed = 100
06 if Humanoid.Walkspeed == 100 then
07Humanoid.Walkspeed = 15
08else
09Humanoid.Walkspeed 100
10end
11script.Parent.MouseButton1Click:connect(onClick)
0
You always set the WalkSpeed to 100 at the beginning, then you always check if it is equal to 100, and it always is, because you just set it, so after clicking once (or many times) the WalkSpeed will always be 15. duckwit 1404 — 8y
0
okay IfIWasntSoSwag 98 — 8y

3 answers

Log in to vote
0
Answered by 8 years ago

local Player = game.Players.LocalPlayer

local Humanoid = Player.Character.Humanoid

function onClick()

Humanoid.Walkspeed = 100

if Humanoid.Walkspeed == 100 then Humanoid.Walkspeed = 15

else

1Humanoid.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.

Ad
Log in to vote
0
Answered by 8 years ago
1local Player = game.Players.LocalPlayer
2local Hum = Player.Character:WaitForChild("Humanoid")
3script.Parent.MouseButton1Click:connect(function()
4if Hum.Walkspeed >= 100 then
5Hum.Walkspeed = 15
6else
7Hum.Walkspeed = 100
8end
9end)
Log in to vote
0
Answered by 8 years ago
Edited 8 years ago

Put this script in a textbutton inside a screen gui or where ever. Boom.

01local player = game.Players.LocalPlayer
02 
03 
04function 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 
13script.Parent.MouseButton1Click:connect(whenClicked)

This has been tested and works.

Answer this question