Hi, frankly I am horrified by this code. But don't worry, we've all been there! What you're missing are loops
, in the case specifically, we're looking for for
loops.
for
loops allow you to run lines of code a specified number of times without needing to type all of them out.
Example:
1 | local Part = workspace.Part |
5 | Part.CFrame = CFrame.new(Part.Position + Vector 3. new( 0 , 0.1 , 0 )) |
This code will run the wait
and the Part.CFrame =
lines 100 times and then continue with the script.
Furthermore, wait(0.001)
can not be done. If you are looking for the fasted wait possible, you can simply write wait()
with no argument. I believe the lowest by default is 0.03 repeating.
To be exact, your problem is that you're treating the variable open_close
as if it were a boolean
value, or a true or false value, when in reality it is not, it's an object. If the object is a BoolValue
like I assume it is, you'll need to add .Value
to the end to specify it's value.
Also, I would use a debounce here to make sure that both open()
and close()
aren't able to fire at the same time, all it does is makes sure you can't click the door until it's either fully open or fully closed.
01 | local door = script.Parent.Parent.Door |
02 | local button 2 = script.Parent.ClickDetector |
03 | local open_close = door.Open_Close |
04 | local sound = script.Parent.Parent.metal_door |
06 | local door_debounce = false |
12 | door.CFrame = CFrame.new(door.Position + Vector 3. new( 0 , 0.1 , 0 )) |
20 | door.CFrame = CFrame.new(door.Position - Vector 3. new( 0 , 0.1 , 0 )) |
24 | button 2. MouseClick:Connect( function () |
25 | if door_debounce then return end |
27 | if open_close.Value = = true then |
28 | open_close.Value = false |
31 | open_close.Value = true |