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

How to have a click detector that destroys multiple bricks when clicked?

Thank you For your time and afford to solve my problem I appreciate your help any help.

hi I wanna have a script that destroys all individual bricks when clicked on that brick this is what i have i put into every brick in the world a click detector then loop through those click detectors for a click


for i,clickdetectors in pairs(clicktest) do
	print("hhh")
	clickdetectors.RightMouseClick:connect(function()
		deleteevent:FireServer(clickdetectors.Parent)
		print("hit")
		
	end)
	  
end

thanks, I really appreciate your help and your knowledge thanks.

2 comments

0

are you trying to, when a player clicks one part, they all get destoryed?

0

hi marine5575 if a player clicks a part only that part get's destroyed not the others

2 answers

✓ Accepted answer

You can't use for loops with click detectors, instead paste this script into every click detector

clickdetector.MouseClick:Connect(function() -- Change clickdetector to the path of the click detector, e.g if you have the script inside the click detector it would be script.Parent.MouseClick etc. etc.
script.Parent.Parent:Destroy() -- Assuming the click detector is in a brick / part and the script is in the click detector



You also don't need a remote event, do all this in a server script!

If I helped please accept this answer!

2 comments

0

HI zomspi thanks for your help but i did everything you said and put in everyclickdetector an script but still it does not work

0

here is the script i put in every clickdetector --- local clickdetector=script.Parent clickdetector.RightMouseClick:Connect(function() script.Parent.Parent:Destroy() end)

This, with a cool statement.

--Server script
local Clicked = false
for i,clickdetector in pairs(clicktest) do
    print("Index:" .. i .. " is listening...")
    local Listener = clickdetector.MouseClick:connect(function()
	if Clicked == false then
        	deleteevent:FireServer()
		print("hit")
		Clicked = true
	else
		Listener:Disconnect()
	end
    end)
end
------Server script inside the Delete event
local event = script.Parent
local MultiplePartModel--You know
local signal = event.OnServerEvent:Connect(function(plr)
	MultiplePartModel:Destroy()
	print("Destroyed.")
end)

or this script which didn't modify the clickdetectors.Parent part.

--Server script SECOND CHOICE, MIGHT ERROR
local Clicked = false
for i,clickdetector in pairs(clicktest) do
    print("Index:" .. i .. " is listening...")
    local Listener = clickdetector.MouseClick:connect(function()
	if Clicked == false then
        	deleteevent:FireServer(clickdetector.Parent)
		print("hit")
		Clicked = true
	else
		Listener:Disconnect()
	end
    end)
end
------Server script inside the Delete event
local event = script.Parent
local signal = event.OnServerEvent:Connect(function(plr,model)
	model.Parent:Destroy()
	print("Destroyed.")
end)

1 comment

0

hi StormArmy1153 it shows ClickDetector is not a valid member of ClickDetector

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