There is this gate script I found in free models, which I'm rather fond of because of the lever motion. However in the current state of the script a player clicks lever; lever moves (open position); gate opens; player clicks to close; lever moves (close position); gate closes;
I want to try change it so that the order is then: player clicks lever; lever moves (open position); lever moves (close position); gate opens; wait 1 second; gate closes.
The model has three parts with a script, 'lever' model and 'portcullisgate' model. The 'lever' and 'portcullisgate' models both have Boolvalues labelled 'Open'.
Script part has this:
script.Parent.Lever.UpDown.Changed:connect(function() script.Parent.PortcullisGate.Open.Value = true end)
The 'lever' model has this script in it (A lot of this script is connecting two lever parts together at the right angle).
local divs = 32 local time = 0.5 local dist = math.pi / 8
local progress = 0 local direction = 1
function positionLever(angle) local base = script.Parent.LeverBase.CFrame local transform = CFrame.fromEulerAnglesXYZ(angle, 0, 0) * CFrame.new(0, 1, 0)
script.Parent.Lever.CFrame = (base * CFrame.new(0, 0.5, 0)) * transform
end
local ang = math.pi / 4 positionLever(ang) script.Parent.Lever.ClickDetector.MouseClick:connect(function() if progress ~= 0 then return end
direction = -direction while true do if progress >= divs then script.Parent.UpDown.Value = not script.Parent.UpDown.Value progress = 0 break end progress = progress + 1 ang = ang + ((dist / divs) * direction) positionLever(ang) wait(time / divs) end
end)
'Portcullisgate' model has this script in:
local divs = 32 local time = 0.5 local dist = math.pi / 8
local progress = 0 local direction = 1
function positionLever(angle) local base = script.Parent.LeverBase.CFrame local transform = CFrame.fromEulerAnglesXYZ(angle, 0, 0) * CFrame.new(0, 1, 0)
script.Parent.Lever.CFrame = (base * CFrame.new(0, 0.5, 0)) * transform
end
local ang = math.pi / 4 positionLever(ang) script.Parent.Lever.ClickDetector.MouseClick:connect(function() if progress ~= 0 then return end
direction = -direction while true do if progress >= divs then script.Parent.UpDown.Value = not script.Parent.UpDown.Value progress = 0 break end progress = progress + 1 ang = ang + ((dist / divs) * direction) positionLever(ang) wait(time / divs) end
end)
I don't know much about script and have tried figuring out how to use the wait command but I just can't work out where to put such a command. I'll be really grateful for any help.