Hello, I want to make a gate that operates on multiple levers that have to be pulled down, they are also timed.
I am unsure how I should approach this without writing several functions, if you could take a gander at this and point me in a direction I should take I would appreciate it.
if v.Name == "MultiGate" then -- Multi Lever Gate
local leverGate = v
local Levers = {
leverGate.Lever1,
leverGate.Lever2,
leverGate.Lever3
}
local ggate = leverGate.Gate
ggate.CanCollide = true
local gorigin = ggate.CFrame
local gtarg = gorigin*CFrame.new(0,ggate.Size.y-1,0)
local lorigin1 = Levers.CFrame*CFrame.Angles(0,math.rad(0),math.rad(0))
local ltarg1 = Levers.CFrame*CFrame.Angles(60,math.rad(0),math.rad(0))
local gateClosed = true
local switches = 0
local function Lever(pl)
local ch = pl and pl.Character
if pl and not ch then return end
local hum = ch and ch:FindFirstChild("Humanoid")
if ch and not hum then return end
if hum and hum.Health <= 0 then return end
local curtime = tick()
Levers.ClickDetector.MaxActivationDistance = 0
for i = 0,1,0.05 do
Levers.CFrame = lorigin1:lerp(ltarg1,i)
wait()
end
Levers.CFrame = ltarg1
switches += 1
print("Plus one")
wait(5)
for i = 0,1,0.05 do
Levers.CFrame = ltarg1:lerp(lorigin1,i)
wait()
end
Levers.CFrame = lorigin1
switches -= 1
Levers.ClickDetector.MaxActivationDistance = 10
end
local function toggleGate()
local curtime = tick()
if switches ~= 3 then return end
print("ToggleGate Confirmed")
ggate.Sound:Play()
if gateClosed then
gateClosed = false
for i = 0,1,0.05 do
ggate.CFrame = gorigin:lerp(gtarg,i)
wait()
end
ggate.CFrame = gtarg
wait(5)
ggate.Sound:Play()
gateClosed = true
for i = 0,1,0.05 do
ggate.CFrame = gtarg:lerp(gorigin,i)
wait()
end
ggate.CFrame = gorigin
end
wait(0.5)
end
Levers.ClickDetector.MouseClick:connect(Lever)
spawn(function()
while true do
toggleGate()
wait()
end
end)
end