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

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

	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

Instead of

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

use

iscrouching = not iscrouching

2 comments

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.

0

This helped, but I had to do a lot of other things to fix it.

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