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

Speed Script, How do I make the speed reset?

Asked by 5 years ago

I've made this speed script however I was wondering how can I make this script if it were to executed again the speed would reset back to normal or remove it however when I click it again it should come back

game:GetService("UserInputService").InputBegan:connect(function(inputObject,gameProcessedEvent)
    if inputObject.KeyCode == Enum.KeyCode.W then
        game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 200
    end 
end)

1 answer

Log in to vote
2
Answered by
RubenKan 3615 Moderation Voter Administrator Community Moderator
5 years ago
Edited 5 years ago

You'd simply need an extra if statement to check if it was enabled last time, you can also do this in one line using the and and or operators when asigning a variable.

Some explaination

Pretty much what this does is, if the first value is true, use the and, else use the or.

Here are some examples.

local var = true and 1 or 2 would be 1,

local var = false and 1 or 2 would be 2,

local var = true and 1 and 2 or 3 would be 2

local var = false and 1 or 2 and 3 would be 3, as a number is not nil or false, thus thrutly

Code

local Player = game.Players.LocalPlayer
game:GetService("UserInputService").InputBegan:connect(function(io,GPE)
    if not GPE and io.KeyCode == Enum.KeyCode.W then
        Player.Character.Humanoid.WalkSpeed = 
        Player.Character.Humanoid.WalkSpeed == 200 and 16 or 200
    end 
end)

0
This is A Bad method Ziffixture 6913 — 5y
0
ur a bad method Gey4Jesus69 2705 — 5y
0
This is a very good method. User#25115 0 — 5y
Ad

Answer this question