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 7 years ago
Edited 7 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

local Player = game.Players.LocalPlayer
local Humanoid = Player.Character.Humanoid

function onClick()
Humanoid.Walkspeed = 100
 if Humanoid.Walkspeed == 100 then
Humanoid.Walkspeed = 15
else
Humanoid.Walkspeed 100
end
script.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 — 7y
0
okay IfIWasntSoSwag 98 — 7y

3 answers

Log in to vote
0
Answered by 7 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

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.

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

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

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

local player = game.Players.LocalPlayer


function whenClicked()
    if player.Character.Humanoid.WalkSpeed == 16 then
        player.Character.Humanoid.WalkSpeed = 100
    else if player.Character.Humanoid.WalkSpeed == 100 then
        player.Character.Humanoid.WalkSpeed = 16
    end
    end
    end

script.Parent.MouseButton1Click:connect(whenClicked)

This has been tested and works.

Answer this question