Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

1 comment

0

Bookmarked. I'll write some code for you when I wake up!

2 answers

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.

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

This discussion is preserved as it was. New answers, comments, and votes are closed.