Trying to create a debounce of some sort to check if its true or false for the motors to move
Where it says “elseif down == false then” it says “Type TRUE cannot be compared to FALSE”
Ive tried searching this problem up on the devfourm with no luck
local equipped = false
local tool = script.Parent
local down = true
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local Plane = if player.Character then player.Character:FindFirstChild("Plane") else nil
local MainPart = Plane.MainParts
local UIS = game:GetService("UserInputService")
tool.Equipped:Connect(function()
equipped = true
print("EQUIPED")
if equipped == true and down == true then
UIS.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.G then
down = false
MainPart.Main.LGFMotor.DesiredAngle = 1.5
MainPart.Main.LGRMotor.DesiredAngle = -1.5
MainPart.Main.LGLMotor.DesiredAngle = -1.5
print("DOWN")
elseif down == false then
if input.KeyCode == Enum.KeyCode.G then
MainPart.Main.LGFMotor.DesiredAngle = 0
MainPart.Main.LGRMotor.DesiredAngle = 0
MainPart.Main.LGLMotor.DesiredAngle = 0
down = false
print("UP")
end
end
end)
end
end)
tool.Unequipped:Connect(function()
equipped = false
end)
I know my code is messy but im going to fix it later just right now i dont understand how to fix it and what the problem. When i click g it says print "DOWN"which is does but when i click g again it just prints "DOWN"again when it should say “UP” and the motors to change?
You’re checking if down is false in a block where down is guaranteed to be true.
if equipped == true and down == true then -- The below code will only execute if down is true...
UIS.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.G then
down = false
MainPart.Main.LGFMotor.DesiredAngle = 1.5
MainPart.Main.LGRMotor.DesiredAngle = -1.5
MainPart.Main.LGLMotor.DesiredAngle = -1.5
print("DOWN")
elseif down == false then -- This elseif is in the wrong block... how could down be false?
if input.KeyCode == Enum.KeyCode.G then
MainPart.Main.LGFMotor.DesiredAngle = 0
MainPart.Main.LGRMotor.DesiredAngle = 0
MainPart.Main.LGLMotor.DesiredAngle = 0
down = false
print("UP")
end
end
end)
end
local equipped = false
local tool = script.Parent
local down = true
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local Plane = if player.Character then player.Character:FindFirstChild("Plane") else nil
local MainPart = Plane.MainParts
local UIS = game:GetService("UserInputService")
local debounce = false
tool.Equipped:Connect(function()
equipped = true
print("EQUIPPED")
UIS.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.G and not debounce then
debounce = true
if down then
MainPart.Main.LGFMotor.DesiredAngle = 1.5
MainPart.Main.LGRMotor.DesiredAngle = -1.5
MainPart.Main.LGLMotor.DesiredAngle = -1.5
down = false
print("DOWN")
else
MainPart.Main.LGFMotor.DesiredAngle = 0
MainPart.Main.LGRMotor.DesiredAngle = 0
MainPart.Main.LGLMotor.DesiredAngle = 0
down = true
print("UP")
end
wait(0.5)
debounce = false
end
end)
end)
tool.Unequipped:Connect(function()
equipped = false
end)