UIS.InputBegan:Connect(function(Input,IsTyping)
if IsTyping then
return
elseif Input.KeyCode == Enum.KeyCode.Q then
local Newstate = not SuitedUp
local CurrentState = SuitedUp
SuitedUp = Newstate
if CurrentState then
SuitUp:FireServer()
else
SuitDown:FireServer()
end
end
end)
The issue here is that i have to activate the input twice before the script fires the function instead of once like i intended to, so I figured the issue lies with my booleans but i’m not exactly sure.
That is because “CurrentState” starts out as false, you change the NewState, but you don’t change the “CurrentState”, so after one press the current state stays as false. Try this:
UIS.InputBegan:Connect(function(Input,IsTyping)
if IsTyping then
return
elseif Input.KeyCode == Enum.KeyCode.Q then
local Newstate = not SuitedUp
local CurrentState = Newstate
SuitedUp = Newstate
if CurrentState then
SuitUp:FireServer()
else
SuitDown:FireServer()
end
end
end)
Yeah sure!!! This is your original script. The reason yours doesn’t work is that you set CurrentState = Suited Up before you change Suited Up. I make these mistakes all the time, what I would recommend is to use a ton of print statements to find the problem. When you see what is wrong, go step by step of what is going to happen at each line, and you will find the problem.
SuitedUp = false
--1 Click
NewState = not SuitedUp
therefore NewState = true
CurrentState = SuitedUp
therefore CurrentState= false
SuitedUp = NewState
therefore SuitedUp = true
--if statement sees that CurrentState is false, fires SuitDows
--2 Clicks
NewState = not SuitedUp
therefore NewState = false
CurrentState = SuitedUp
therefore CurrentState= true
SuitedUp = NewState
therefore SuitedUp = false
--if statement sees that CurrentState is true, it works this time