I am trying to make a gate that opens for 5 seconds. I have two models, one is visible and stays on the ground "closedgate" and there is another one that is floating above it and is usually invisible "opengate" I'm trying to change the properties of the parts inside of the models so there is an effect of the door opening when a button is pressed.
This is the code I have currently.
local button = script.Parent
local closedgate = workspace.ClosedGate:GetChildren() --gets children of closed gate model
local opengate = workspace.OpenGate:GetChildren() --gets children of open gate model
local function openGate()
print("Click Detected")
closedgate.Transparency = 1 --makes the gate invisible
closedgate.CanCollide = false --makes player able to walk through gate
opengate.Transparency = 0 --makes floating gate visible
print("Gate Opened")
wait(5)
closedgate.Transparency = 0 --makes gate visible
closedgate.CanCollide = true --makes player unable to walk through gate
opengate.Transparency = 1 --makes floating gate invisible
print("Gate Closed")
end
button.ClickDetector.MouseClick:Connect(openGate) --runs opengate function when clicked

1 comment
if there is a script inside the model, it will have an error because you didn't check if v was a basepart