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

ClickDetector removes itself and then Clones another one somewhere else?

Asked by 8 years ago

So, here is a detailed list of what happens

-CLOSED have the ClickDetectors -OPEN and CLOSED have the scripts -When CLOSED is clicked, it's CD's are removed and the OPEN have a ClickDetector Cloned -When OPEN is clicked, it's CD's are removed and the CLOSED have a ClickDetector Cloned.

OPEN:

local OPEN = script.Parent.Parent.OPEN
local CLOSED = script.Parent.Parent.CLOSED

function onClick()
    OPEN.Transparency = 1
    OPEN.CanCollide = false 
    OPEN.ClickDetector:Destroy()
    wait(0.5)
    CLOSED.Transparency = 0
    CLOSED.CanCollide = true
    CLOSED:Clone(game.Lighting.ClickDetector)
end

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

CLOSED:

local OPEN = script.Parent.Parent.OPEN
local CLOSED = script.Parent.Parent.CLOSED

function onClick()
    CLOSED.Transparency = 1
    CLOSED.CanCollide = false   
    CLOSED.ClickDetector:Destroy()
    wait(0.5)
    OPENTransparency = 0
    OPEN.CanCollide = true
    OPEN:Clone(game.Lighting.ClickDetector)
end

script.Parent.ClickDetector.MouseClick:connect(onClick)
0
I dont think the way you used :Clone() is right. Kyokamii 133 — 8y
0
^ Then how do I use it? Wiki/Wikia ain't of any help :/ TheHospitalDev 1134 — 8y

1 answer

Log in to vote
1
Answered by 8 years ago

You seem no not be using the clone command correctly. Take your line:

OPEN:Clone(game.Lighting.ClickDetector)

This isn't correct. Try,

OPEN:Clone().Parent=game.Lighting.ClickDetector

Now simply fix your remaining code up and we get:

OPEN:

local OPEN = script.Parent.Parent.OPEN
local CLOSED = script.Parent.Parent.CLOSED

script.Parent.ClickDetector.MouseClick:connect(function())
    OPEN.Transparency = 1
    OPEN.CanCollide = false 
    OPEN.ClickDetector:Destroy()
    wait(0.5)
    CLOSED.Transparency = 0
    CLOSED.CanCollide = true
    CLOSED:Clone().Parent=game.Lighting.ClickDetector
end)

CLOSED:

local OPEN = script.Parent.Parent.OPEN
local CLOSED = script.Parent.Parent.CLOSED

script.Parent.ClickDetector.MouseClick:connect(function())
    CLOSED.Transparency = 1
    CLOSED.CanCollide = false   
    CLOSED.ClickDetector:Destroy()
    wait(0.5)
    OPENTransparency = 0
    OPEN.CanCollide = true
    OPEN:Clone().Parent=game.Lighting.ClickDetector
end)

If this helped, please accept and upvote!

~Chem

Ad

Answer this question