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

How can i detect the player if he has the tool?

Asked by 5 years ago
Edited 5 years ago

Example , If the player has a LeverHolder, and He clicked on the broken lever, the broken lever will be fix and his level in his inventory will dissapear? can anyone help?

I also tried

script.Parent.ClickDetector.MouseClick:Connect(function()
    local player = game.Players.LocalPlayer

    player.Backpack:WaitForChild("Lever"):Destroy()
end)

1 answer

Log in to vote
2
Answered by
DanzLua 2879 Moderation Voter Community Moderator
5 years ago
Edited 5 years ago

We can simply look inside the player's backpack to that certain instance.

Assuming this is being done through a clickdetector.

part.ClickDetector.MouseClick:Connect(function(plr)
    if plr.Backpack:FindFirstChild("LeverHolder") then
        --dostuff
    end
end)

What if this was a Tool? The player could equip it and it would no longer be in the Backpack, now we have to check if it is in the character.

part.ClickDetector.MouseClick:Connect(function(plr)
    if plr.Backpack:FindFirstChild("LeverHolder") or plr.Character:FindFirstChild("LeverHolder") 
        --dostuff
    end
end)
0
great answer User#23252 26 — 5y
0
Thanks so much! Minecrafter09031031 16 — 5y
Ad

Answer this question