so im making a door for my border game but the door script doesnt seem to work? well, it works, but the door ONLY expands down and doesnt retract. heres the script:
local gate = script.Parent local button = gate.Parent["gate button"] local clickdetector = button.ClickDetector local debounce = false local opened = false clickdetector.MouseClick:Connect(function() if debounce then return end if opened == true then debounce = true for i = 16.5,0.5,0.25 do gate.Position = gate.Position - Vector3.new(0,0.125,0) gate.Size = gate.Size + Vector3.new(0,0.25,0) end opened = false debounce = false end if opened == false then debounce = true for i = 16.5,0.5,0.25 do wait(0.1) gate.Position = gate.Position + Vector3.new(0,0.125,0) gate.Size = gate.Size - Vector3.new(0,0.25,0) end opened = true debounce = false end end)
thank you for your help :p
Just use an else because it's a bool, it can only hold 2 values.
local gate = script.Parent local button = gate.Parent["gate button"] local clickdetector = button.ClickDetector local debounce = false local opened = false clickdetector.MouseClick:Connect(function() if debounce then return end if opened == true then debounce = true for i = 16.5,0.5,0.25 do gate.Position = gate.Position - Vector3.new(0,0.125,0) gate.Size = gate.Size + Vector3.new(0,0.25,0) end opened = false debounce = false end else debounce = true for i = 16.5,0.5,0.25 do wait(0.1) gate.Position = gate.Position + Vector3.new(0,0.125,0) gate.Size = gate.Size - Vector3.new(0,0.25,0) end opened = true debounce = false end end)
apparently the for loop was wrong :/ it didnt run because the for loop was already finished (startervalue was 16.5 and finish value was 0.5, so, technically it was more than finished?) fixed version:
local gate = script.Parent.Parent.Gate local button = script.Parent local clickdetector = script.Parent.ClickDetector local debounce = false local opened = false clickdetector.MouseClick:Connect(function(plr) print("yease") if debounce == true then return end if opened == true then print("its opend but its now closing") debounce = true for XVI = 0.5,16.5,0.25 do wait(0.1) gate.Position = gate.Position - Vector3.new(0,0.125,0) gate.Size = gate.Size + Vector3.new(0,0.25,0) end opened = false debounce = false else print("its closd but its now opening") debounce = true for XVI = 0.5,16.5,0.25 do wait(0.1) gate.Position = gate.Position + Vector3.new(0,0.125,0) gate.Size = gate.Size - Vector3.new(0,0.25,0) end opened = true debounce = false end end)