Can a local script detect if a player has clicked a clickdetector without identifying the clickdetector

Basically i have like a folder with a tone of different models that have parts and some parts have click detectors.

I don’t want to have to write a whole code to locate all the click detectors

Is there anyway I can identify if a click detector has been clicked on using mouse properties or something?

I think it would simpler to get every clickdetector and do something than make complex code to detect if you click and the mouse is on a part with a clickdetector. It’s not that hard to get every clickdetector and do something

local model = --Your model
local player = game.Players.LocalPlayer

for _,v in pairs(model:GetDescendants()) do
	if v:IsA("ClickDetector") then
		v.MouseClick:Connect(function(plr)
			if plr.Name ~= player.Name then return end --A condition to confirm clicker is the local player
			print("Clicked on a detector")
		end)
	end
end
1 Like

Yeah your right.
I just wrote a similar code while waiting I just thought it woulda been a lot longer.

Although another question would be. How can you call a function on a player double clicking on a click detector?

if you haven’t already worked out I don’t have much experience with click detectors

There’s no built in for that, you’d have to do it yourself

local model = --Your model
local player = game.Players.LocalPlayer

for _,v in pairs(model:GetDescendants()) do
	if v:IsA("ClickDetector") then
		v:SetAttribute("HasClicked", false)
		v.MouseClick:Connect(function(plr)
			if plr.Name ~= player.Name then return end
			local attrib = v:GetAttribute("HasClicked")
			if attrib then
				print("Double Clicked on a detector")
			end
			v:SetAttribute("HasClicked", not attrib)
		end)
	end
end

A simple way to do that would be this, although the double click can be done anytime, so you cna have one click, wait 10 seconds, and then click agian to activate it

I can fix it up a bit to make it like an actual doubleclick like we have if needed

2 Likes

Yep its working perfectly now Thank you for all the help

1 Like

Anytime! If you have anymore issues don’t be afraid to make another post!

1 Like