My script is below.
base = script.Parent.Parent.Parent dtop = base.SecurityDoor.TopDoor dbottom = base.SecurityDoor.BottomDoor function onClicked() for i = 1, 10 do dtop.Position.Vector3 = CFrame.new() + Vector3.new(0,1,0) dbottom.Position.Vector3 = CFrame.new() + Vector3.new(0,1,0) break end end script.Parent.ClickDetector.MouseClick:connect(onClicked)
To be specific, I want the parts to go in a single direction by one stud for every loop. Both the TopDoor and BottomDoor are Unions.
This is for my security door. When you click the brick within the Biometric Scanner, it scans your Access Level and, if your Access Level meets or exceeds the minimum, then the script opens the door.
Ok, so you had a few errors here. I'll take you through them step by step, and give you the finished script at the end.
for i = 1, 10 do dtop.Position.Vector3 = CFrame.new() + Vector3.new(0,1,0) dbottom.Position.Vector3 = CFrame.new() + Vector3.new(0,1,0) break end
(This chunk is basically where all your errors took place)
First of all, you did:
dtop.Position.Vector3 dbottom.Position.Vector3
This is incorrect because there is no Property for Vector3
. Vector3
is a DataType that is used to set physical traits of an object such as Position, Size, Velocity ect. To use Vector3
correctly, you need to do something like this:
dtop.Position = Vector3.new(1,5,1)
Secondly, you tried to add the CFrame
Position, and Vector3
Position of the objects together.
CFrame.new() + Vector3.new(0,1,0)
You also cannot do this. This results in errors, because DataTypes can only be used with their own DataType. Also, you left the arguments in the first part empty. That sets the initial position. To fix this, we'll change the entire script to using CFrame
instead of using CFrame
and Vector3
, and then we'll fill in those values:
dtop.CFrame = CFrame.new(dtop.Position) * CFrame.new(0,1,0) --Also, change to multiplication, not addition dbottom.CFrame = CFrame.new(dbottom.Position) * CFrame.new(0,1,0) -- ^ Idk why it's like that honestly.
lastly, you had a break in the loop.
break
When you use a break, it ends the current loop that's running. Breaks don't normally need to be used unless you have a function that can run indefinitely which can become an infinite loop. When you used it in your function, it ended the current loop that was running, so that it only moved the blocks up once before it was removed.
Now for the finished script!
base = script.Parent.Parent.Parent dtop = base.SecurityDoor.TopDoor dbottom = base.SecurityDoor.BottomDoor function onClicked() for i = 1, 10 do wait() --I added this because I assumed you would like to see the doors actually moving, instead of having them teleport up/down. dtop.CFrame = CFrame.new(dtop.Position) * CFrame.new(0,1,0) dbottom.CFrame = CFrame.new(dbottom.Position) * CFrame.new(0,1,0) end end script.Parent.ClickDetector.MouseClick:connect(onClicked)
So, I cleaned up your script a bit, and I believe I fixed pretty much everything that was wrong with it. I understand this can be alot to try to learn all at once, so if you have any further problems/questions, please leave a comment below. Hope I helped :P