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

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

Asked by 7 years ago

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

Log in to vote
0
Answered by
xPolarium 1388 Moderation Voter
7 years ago
Edited 7 years ago

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.

0
Thanks! OMG_Gaming404 73 — 7y
Ad

Answer this question