Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

why does my button door not work at all? i dont know what I did wrong

Asked by 5 years ago
Edited 5 years ago

I made a simple door that, if you press the button, the door should lift up. There is a value that states if it is open or closed or not. It doesn't work for some reason. I need to mention 4 things before I show the script:

  1. I do NOT know how to tween (im an amutuer i know)
  2. It uses CFrame and Vector3 to make it slide
  3. there are 2 buttons, so when it says button1, it refers to the first button
  4. It's a long script (which like i said i dont know how to tween)

with that being said here is the script.

001local door = script.Parent.Parent.Door
002local button2 = script.Parent.ClickDetector
003local open_close = door.Open_Close
004local sound = script.Parent.Parent.metal_door
005 
006local function open()
007    sound:Play()
008    door.CFrame = CFrame.new(door.Position + Vector3.new(0, 0.1, 0))
009    wait(0.001)
010    door.CFrame = CFrame.new(door.Position + Vector3.new(0, 0.1, 0))
011    wait(0.001)
012    door.CFrame = CFrame.new(door.Position + Vector3.new(0, 0.1, 0))
013    wait(0.001)
014    door.CFrame = CFrame.new(door.Position + Vector3.new(0, 0.1, 0))
015    wait(0.001)
View all 138 lines...

edit: fixed, thanks to repgainer3. thank you so much.

1 answer

Log in to vote
0
Answered by 5 years ago

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:

1local Part = workspace.Part
2 
3for i = 1, 100 do
4    wait(0.1)
5    Part.CFrame = CFrame.new(Part.Position + Vector3.new(0, 0.1, 0))
6end

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.

01local door = script.Parent.Parent.Door
02local button2 = script.Parent.ClickDetector
03local open_close = door.Open_Close
04local sound = script.Parent.Parent.metal_door
05 
06local door_debounce = false
07 
08function open()
09    sound:Play()
10    for i = 1, 29 do
11        wait()
12        door.CFrame = CFrame.new(door.Position + Vector3.new(0, 0.1, 0))
13    end
14end
15 
View all 36 lines...
0
oh my gosh, thank you so much. I'm going to try this right now MrCreepyPeach 22 — 5y
Ad

Answer this question