I wasn't sure if your gate was a model or a part so I showed how to do both:
#If Gate is one part do the following:
To add/subtract from a CFrame's position, you'd want to multiply the current CFrame by another CFrame value.
The second CFrame value is amount you want to offset your part.
I changed the name of your position variable to be gateCFrame. The code to move the gateOver would be the following:
adding to position
gate.CFrame= gate.CFrame* CFrame.new(Vector3.new(0,1,0))
subtracting from position:
gate.CFrame= gate.CFrame* CFrame.new(Vector3.new(0,1,0))
The whole script would be:
detector = script.Parent
gate = game.Workspace.Gate
open = false
detector.MouseClick:Connect(function()
if open == false then
detector.MaxActivationDistance = 0
for i = 1,17 do
print("moved")
gate.CFrame= gate.CFrame* CFrame.new(Vector3.new(0,1,0))
wait(0.5)
end
detector.MaxActivationDistance = 15
open = true
else
detector.MaxActivationDistance = 0
for i = 1,17 do
print("moved")
gate.CFrame= gate.CFrame* CFrame.new(-Vector3.new(0,1,0))
wait(0.5)
end
open = false
detector.MaxActivationDistance = 15
end
end)
#If Gate is a model, do the following:
You can't change the cframe of a model directly since models don't have a cframe property. Instead, we need to give gate a primary part by changing the primary part property of the Gate model.
Instead of the above code where we set the CFrame of the gate part, we're going to set the CFrame of the primary part inside of the model. To do that we'd say:
Adding to position:
gate:SetPrimaryPartCFrame(gate.PrimaryPart.CFrame * CFrame.new(Vector3.new(0,1,0)))
Subtracting from position: (make the vector 3 a negative so one is now -1)
gate:SetPrimaryPartCFrame(gate.PrimaryPart.CFrame * CFrame.new(-Vector3.new(0,1,0)))
7 comments
Well I selected your answer too early it seems. The gate is a union, but I tested this on a regular part as well and it got the same result. The loops are working as intended but the part is not actually moving in-game.
Try moving it without any of the other code to see if it's an issue with the loops or to see if it's an issue with the logic
I.e. try: gateCFrame = gateCFrame * CFrame.new(Vector3.new(0,1,0))
wait im dumb i'll change the answer
Should be gate.CFrame= gate.CFrame* CFrame.new(Vector3.new(0,1,0)). You were initially just changing the CFrame in the gateCFrame variable, not changing CFrame itself
This worked, thanks.
im glad