How to determine which part a player clicked?

There’s a folder of parts and each part has a ClickDetector. When an individual part is clicked, I need to change certain properties of the part that was clicked. I’m not sure if this is the most efficient way of setting this up, but I can’t seem to figure out how to pass on the name of the part as a parameter through MouseClick:Connect.

function Scan_Part(Player)
   local Player = game.Workspace[Player.Name]
   if Player:FindFirstChild("Specific_Tool") then
      Part.Transparency = 1
      print("Property of " .. Part .. " has been successfully changed!")
   end
end

for Each, Part in pairs(game.Workspace.PartFolder:GetChildren()) do
   Part.ClickDetector.MouseClick:Connect(Scan_Part)
end

How do I make sure that ‘Part.Transparency = 1’ changes the properties of the specific part that the player clicked on in MouseClick:Connect?

1 Like

I’m not sure how to do that but here’s an alternative:

for _, Part in pairs(game.Workspace.PartFolder:GetChildren()) do
	Part.ClickDetector.MouseClick:Connect(function(Player)
		local Character = game.Workspace[Player.Name]
		if Character:FindFirstChild("Specific_Tool") then
			Part.Transparency = 1
			print("Property of " .. Part .. " has been successfully changed!")
		end
	end)
end
3 Likes

I apologize for the late reply; I made this post minutes before going to work. Your solution is perfect and works as intended. Thank you so much!

1 Like