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

How do I make a clickdetector of one part affect other?

Asked by 3 years ago

I want to make a door that that opens when you click a button, although I am unsure how to do it.

I am new to ClickDetector

0
Bookmarked. I'll write some code for you when I wake up! zane21225 243 — 3y

2 answers

Log in to vote
1
Answered by 3 years ago
Edited 3 years ago

ClickDetector is pretty easy, you utilize MouseClick event that fires once the player clicks its parent. Insert a ClickDetector in the part where you want to click to. Then insert a script not LocalScript inside also the part where you want to click to.

local clickDetector = script.Parent.ClickDetector
local door = game.Workspace.DoorName

local open = false

clickDetector.MouseClick:Connect(function(plr)
    if open == false then
        open = true
        door.Transparency = 0.5
        door.CanCollide = false
        -- Door is open
    else
        open = false
        door.Transparency = 0
        door.CanCollide = true
        -- Door is closed
    end
end)

This is just a simple way. You can do a lot more.

Ad
Log in to vote
0
Answered by 3 years ago

You can do something like this:

function OnClicked() 
    script.Parent.Parent.secret.Transparency=1
    script.Parent.Parent.secret.CanCollide=false

    wait (60)

    script.Parent.Parent.secret.Transparency=0
    script.Parent.Parent.secret.CanCollide=true

end 


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

Just change the word secret to the name of the part you want to affect, if the part being affected is called "Part", just rename it to something else.

Hope this helped :D

Answer this question