Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Hello, Would this script work correctly?

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)

2 comments

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.

0

okay

3 answers

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.

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)

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.