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

How to detect when a item appears in a users inventory?

I have a script that kicks a user if they have a certain item in their inventory. But how can I detect when an item is added?

When an item is added i want it to call my itemAdded() function

I currently have this code

function itemAdded(item)
    if item.Name == "HopperBin" then
        item.Parent.Parent:Kick("You are not allowed that item")
    end
end

1 answer

✓ Accepted answer

You can use DescendantAdded() and connect it to the function.

function itemAdded(item)
    if item.Name == "HopperBin" then

	--Changed how we get the Player then we kick
       game.Players:GetPlayerFromCharacter(item.Parent):Kick()
    end
end

--This would check if something was added to Player1's Character Model in Workspace
game.Workspace.Player1.DescendantAdded:connect(itemAdded)

You'll likely need to change the path game.Workspace.Player1 to where the "inventory" is at.

1 comment

0

Thanks!

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