Here's my code:
Detector = script.Parent
Motor1 = script.Parent.Parent.Parent.Parent.Motor1.HingeConstraint
Motor2 = script.Parent.Parent.Parent.Parent.Motor2.HingeConstraint
Invisiblewall = script.Parent.Parent.Parent.Parent.Invisiblewall
Invisiblewall2 = script.Parent.Parent.Parent.Parent.Invisiblewall2 -- Invisible walls stop people jumping over top/glitching through
--Variables
Detector.Touched:Connect(function(hit) -- something touches the detector block on the ticket gate
if hit.Parent.Name == "Ticket" then -- if the thing that hit it is called Ticket then run following code
Invisiblewall.CanCollide = false
Invisiblewall2.CanCollide = false -- Invisible walls now let you through
Motor1.TargetAngle = 70
Motor2.TargetAngle = -70 -- gates open as motor turns them
wait(5)
Motor1.TargetAngle = 0 -- gates close
Motor2.TargetAngle = 0
wait(2)
Invisiblewall.CanCollide = true
Invisiblewall2.CanCollide = true -- invisible walls no longer let you through
end
end)
The code works fine in studio, when you put the ticket tool onto the detector block the invisible walls turn off and the gates swing open and close again after 5 seconds.
It's a script, I tried changing it to a Local script but that made no difference so I changed it back again.

3 comments
where is this script stored?
It's in the model
workspace > Ticketgate > Post1 > Panel > Detector > Script