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

[CLOSED] How do I make this function only fire once (crouch script)?

Asked by 4 years ago
Edited 4 years ago
    require(game.ReplicatedStorage.ControlBinds).Crouch(game.Players.LocalPlayer,iscrouching)
    if iscrouching==false then 
         iscrouching=true
    elseif iscrouching==true then
            iscrouching=false
    end
end

I can't figure out how to make it fire once. I understand what is wrong, it fires and then it sets iscrouching to true which makes the other one fire.

At the end of the function, it always sets iscrouching to false, because iscrouching is set to true once the player crouches, which causes the code that sets it to false to run.

1 answer

Log in to vote
1
Answered by 4 years ago

Instead of

if iscrouching==false then 
     iscrouching=true
elseif iscrouching==true then
     iscrouching=false
end

use

iscrouching = not iscrouching
0
This may not actually fix your problem. Since you used elseif I'm pretty sure the compiler won't even look at the elseif statement if it had set the value to true. Andy_Wirus 72 — 4y
0
This helped, but I had to do a lot of other things to fix it. Void_Frost 571 — 4y
Ad

Answer this question