Im basically trying to make a castle gate open and close, but instead of having it as one large union(which would go through the wall up top) i've divided it into subsections, which will all give the illusion of one large gate when opening/closing. I am trying to have to move as for example an escalator, where one goes down and the other follows.(until it's at it's direct location ofc) I clicked my button and well nothing happened, not sure what caused this since I got see no errors.
Le Script
local Gate = true local Delay = false Gate1 = script.Parent.Parent.Gate1 Gate2 = script.Parent.Parent.Gate2 Gate3 = script.Parent.Parent.Gate3 Gate4 = script.Parent.Parent.Gate4 Gate5 = script.Parent.Parent.Gate local Sound = script.Parent.Sound function GateMoveUp2() for I=1,5 do Gate2.Position=Gate2.Position+Vector3.new(0,0.1,0) wait(.1) end end function GateMoveUp3() for I=1,10 do Gate3.Position=Gate3.Position+Vector3.new(0,0.1,0) wait(.1) end end function GateMoveUp4() for I=1,15 do Gate4.Position=Gate4.Position+Vector3.new(0,0.1,0) wait(.1) end end function GateMoveUp5() for I=1,20 do Gate5.Position=Gate5.Position+Vector3.new(0,0.1,0) wait(.1) end end function GateMoveDown2() for I=1,5 do Gate2.Position=Gate2.Position+Vector3.new(0,-0.1,0) wait(.1) end end function GateMoveDown3() for I=1,10 do Gate3.Position=Gate3.Position+Vector3.new(0,-0.1,0) wait(.1) end end function GateMoveDown4() for I=1,15 do Gate4.Position=Gate4.Position+Vector3.new(0,-0.1,0) wait(.1) end end function GateMoveDown5() for I=1,20 do Gate5.Position=Gate5.Position+Vector3.new(0,-0.1,0) wait(.1) end end script.Parent.ClickDetector.MouseClick:Connect(function() if Delay == false then Delay = true if Gate == true then GateMoveUp2() GateMoveUp3() GateMoveUp4() GateMoveUp5() Sound:Play() Sound.Ended:Wait() Gate=false elseif Gate == false then GateMoveDown2() GateMoveDown3() GateMoveDown4() GateMoveDown5() Sound:Play() Sound.Ended:Wait() Gate=true end Delay = false end end)
You can use SetPrimaryPartCFrame for this, but to do this, you have to set a primary part on the model. go in the properties in the model then click on "PrimaryPart". After clicking, you can choose one of the parts in the gate. Then, insert this in the script:
local Gate = true local Delay = false local ModelGate = script.Parent.Parent local Sound = script.Parent.Sound function OpenGate() for i = 1,(the numbers of loops you want your gate to do) do ModelGate:SetPrimaryPartCFrame(CFrame.new(ModelGate.PrimaryPart.Position + Vector3.new(0,0.1,0))) wait(.1) end end function CloseGate() for i = 1,(the numbers of loops you want your gate to do) do ModelGate:SetPrimaryPartCFrame(CFrame.new(ModelGate.PrimaryPart.Position + Vector3.new(0,-0.1,0))) wait(.1) end end script.Parent.ClickDetector.MouseClick:Connect(function() if Delay == true then Delay = false if Gate == true then OpenGate() Sound:Play() Sound.Ended:Wait() Gate = false return -- returning to the begenning of the function, to not activate the following lines, just after setting gate = false else -- if gate = false CloseGate() Sound:Play() Sound.Ended:Wait() Gate = true end Delay = true end end)
Also, put this in a SERVER script, not inb a LOCAL script.
Hope this helped!