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 4 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 — 4y

2 answers

Log in to vote
1
Answered by 4 years ago
Edited 4 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.

01local clickDetector = script.Parent.ClickDetector
02local door = game.Workspace.DoorName
03 
04local open = false
05 
06clickDetector.MouseClick:Connect(function(plr)
07    if open == false then
08        open = true
09        door.Transparency = 0.5
10        door.CanCollide = false
11        -- Door is open
12    else
13        open = false
14        door.Transparency = 0
15        door.CanCollide = true
16        -- Door is closed
17    end
18end)

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

Ad
Log in to vote
0
Answered by 4 years ago

You can do something like this:

01function OnClicked()
02    script.Parent.Parent.secret.Transparency=1
03    script.Parent.Parent.secret.CanCollide=false
04 
05    wait (60)
06 
07    script.Parent.Parent.secret.Transparency=0
08    script.Parent.Parent.secret.CanCollide=true
09 
10end
11 
12 
13script.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