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
1 | function itemAdded(item) |
2 | if item.Name = = "HopperBin" then |
3 | item.Parent.Parent:Kick( "You are not allowed that item" ) |
4 | end |
5 | end |
You can use DescendantAdded()
and connect it to the function.
01 | function itemAdded(item) |
02 | if item.Name = = "HopperBin" then |
03 |
04 | --Changed how we get the Player then we kick |
05 | game.Players:GetPlayerFromCharacter(item.Parent):Kick() |
06 | end |
07 | end |
08 |
09 | --This would check if something was added to Player1's Character Model in Workspace |
10 | game.Workspace.Player 1. DescendantAdded:connect(itemAdded) |
You'll likely need to change the path game.Workspace.Player1 to where the "inventory" is at.