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

How do you check what the person is clicking?

Hello. I'm trying to make 2 objects that are both the same, and when you click on one of the objects that object that you clicked is destroyed and then respawned, But when I click on the other object the first one still gets destroyed, I'm using a custom click detector, and I'm wondering how you would be able to tell what object the player is clicking, Does anyone know what to do?

Here is the code for the custom click detector:

local Tool = script.Parent 
local mouse = game.Players.LocalPlayer:GetMouse()
local hits = 0
local max_hits = 5
local player = game.Players.LocalPlayer


Tool.Equipped:Connect(function(Mouse)
	Mouse.Button1Down:Connect(function()
		if mouse.Target:FindFirstChild("Clickable") then
			print("You did it") --Testing
			hits = hits + 1
			if hits >= max_hits then
				if hits >= max_hits then
					player.leaderstats.Wood.Value = player.leaderstats.Wood.Value + 1
					wait(3)
			      	 hits = 0
				end 
			end
		end
	end)
end)

1 answer

maybe because you put if hits >= max_hits then twice

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