Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do you check what the person is clicking?

Asked by 3 years ago
Edited 3 years ago

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

Log in to vote
0
Answered by 3 years ago

When answering, if your answer does not fully solve the question, it should be written as a comment to the question instead of as an answer.

maybe because you put if hits >= max_hits then twice

Ad

Answer this question