How to check if something is exist

I want to detect when player is holding something

I’m really bad at scripting tho

3 Likes

as in what a tool? need more specifics

it a tool u correct

[text limit…]

This would go into a local script, if you want the server to know when the player is holding a tool then you would have to use remote events

tool.equiped:Connect(function()
-- Stuff
end)

Or you could use

if player.Character.RightHand:FindFirstChild("tool name") then
3 Likes

You can use :FindFirstChild() to check if something exists, if it exists it returns true.

Example:

if workspace:FindFirstChild('BasePlate') then -- in this case true
   print('Baseplate exists!')
end
6 Likes

Do you want to detect if the player is holding an item? Or detect if this thing is a descendant of something?

Edit: Never mind, I read it wrong.

1 Like
for _, tool in pairs(player.Character:GetDescendants()) do
  if tool:IsA("Tool") then
        print(tool.Name)
    end
end

Remove the RightHand (Unless if it’s a Tool that forcefully goes into the RightHand BasePart of the Character)

There are tons of ways to do this for checking a specific object:

  • You can check via using the Tool.Equipped event which automatically parents the Tool object to the Character Model (As shown in the API)

  • You can call FindFirstChild(), which requires a string parameter (Or a message like “Hi”, “Thank you”, or “Random Tool Object That I Don’t Know What To Put Here”

1 Like
game.Players.PlayerAdded:Connect(function(Player)
        if Player.Backpack:FindFirstChild("") then -- Add the tool name inside the quotations.
        -- Do stuff
    end
end)