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

Scripting error in animated door, makes door handle disappear and no movement. (?)

Asked by 4 years ago

I'm trying to make an animated door (not one that teleport open) but need help as I am really inexperienced with code and practically new to coding.

Code:

function OnClick()
 script.Parent.Transparency = 1
 script.Parent.CanCollide = false
 script.Parent.Parent.OPEN1.Transparency = 0
 script.Parent.Parent.OPEN1.CanCollide = true
 wait(1.5)
 script.Parent.Parent.OPEN1.Transparency = 1
 script.Parent.Parent.OPEN1.CanCollide = false
 script.Parent.Parent.OPEN2.Transparency = 0
 script.Parent.Parent.OPEN2.CanCollide = true
 wait(1.5)
 script.Parent.Parent.OPEN2.Transparency = 1
 script.Parent.Parent.OPEN2.CanCollide = false
 script.Parent.Parent.OPEN3.Transparency = 0
 script.Parent.Parent.OPEN3.CanCollide = true
 wait(1.5)
 script.Parent.Parent.OPEN3.Transparency = 1
 script.Parent.Parent.OPEN3.CanCollide = false
 script.Parent.Parent.OPEN4.Transparency = 0
 script.Parent.Parent.OPEN4.CanCollide = true
 wait(1.5)
 script.Parent.Parent.OPEN4.Transparency = 1
 script.Parent.Parent.OPEN4.CanCollide = false
 script.Parent.Parent.OPEN5.Transparency = 0
 script.Parent.Parent.OPEN5.CanCollide = true
 wait(1.5)
 script.Parent.Parent.OPEN5.Transparency = 1
 script.Parent.Parent.OPEN5.CanCollide = false
 script.Parent.Parent.OPEN6.Transparency = 0
 script.Parent.Parent.OPEN6.CanCollide = true
 wait(1.5)
 script.Parent.Parent.OPEN6.Transparency = 1
 script.Parent.Parent.OPEN6.CanCollide = false
 script.Parent.Parent.OPEN7.Transparency = 0
 script.Parent.Parent.OPEN7.CanCollide = true
 wait(1.5)
 script.Parent.Parent.OPEN7.Transparency = 1
 script.Parent.Parent.OPEN7.CanCollide = false
 script.Parent.Parent.OPEN8.Transparency = 0
 script.Parent.Parent.OPEN8.CanCollide = true
 wait(1.5)
end

script.Parent.ClickDetector.MouseClick:Connect(OnClick)

"OPEN?" These are individual parents in studio, not grouped together. There is other scripts obviously for closing the door and opening it the other way, but they're all based around this.

This code just makes the door handle disappear.

Any tips and hints on how to fix this will be appreciated! Thank you!

0
This isn't the best way to tackle this. I'd rather use TweenService or use a for loop. 1.5 seconds is waaay too long if you want to make a smooth animation. DesertusX 435 — 4y
0
I knoooow! When I looked at how long it was I was like "This isn't going to work". Since I'm not that sure about for loops, I tried a while loop, since the answers didn't work, but at least didn't make the doornob disappear. Still didn't work- but the script was considerably cleaner, so I count it as a win Caesarico 0 — 4y

2 answers

Log in to vote
0
Answered by 4 years ago

So this is a very messy way to go about this. To make your script more simple, you can place all the parts that you want to become transparent inside a folder inside the model. Then use this script outside of the folder in the same model:

local DoorsFolder = script.Parent.FolderName -- Change FolderName to the name of your folder
local Doors = DoorsFolder:GetChildren() -- This places all children of the folder inside a table
local LastDoor = nil
local function OnClick()
    for i, v in ipairs(Doors) do
        if LastDoor == nil then
            return
        else
            LastDoor.Transparency = 1
            LastDoor.CanCollide = false
        end
        v.CanCollide = true
        v.Transparency = 0
        LastDoor = v
        wait(1.5)
    end
end

script.Parent.MouseDetectorPart.ClickDetector.MouseClick:Connect(OnClick()) --Change script.Parent.MouseDetectorPart to your clickdetector directory
Ad
Log in to vote
0
Answered by
DesertusX 435 Moderation Voter
4 years ago

In this answer, I'm using a for loop. I don't know if this will fix our problem but, it's worth a shot.

Since you are new to roblox scripting, I will explain how it works through the script.


local open = {script.Parent.Parent.OPEN1, script.Parent.Parent.OPEN2, script.Parent.Parent.OPEN3, script.Parent.Parent.OPEN4, script.Parent.Parent.OPEN5, script.Parent.Parent.OPEN6, script.Parent.Parent.OPEN7, script.Parent.Parent.OPEN8}
--This is a table. These hold information.

function OnClick()
    for i, door in pairs(open) do --We are looping through or passing through everything in the table we already defined before.
        wait(0.1)
        door.Transparency = 0
        door.CanCollide = true
        if i ~= 1 then --If the door we are looping through is not the first, then..
            local recentDoor = open[i - 1] --The door before
            recentDoor.Transparency = 1
            recentDoor.CanCollide = false
        end
    end
end

script.Parent.ClickDetector.MouseClick:Connect(onClick)


Hope this helped! Don't forget to accept the answer if it did!!

Answer this question