I was testing with print lines and it would not print when I got to the if statement(line 5). I own the game pass but the code wont work. There are no errors in the output.
01 | local newItem = game.ReplicatedStorage:FindFirstChild( "InfBag" ):Clone() |
02 | capacityEvent = game.ReplicatedStorage:WaitForChild( "UICapacityEvent" ) |
03 | game.Players.PlayerAdded:Connect( function (player) |
04 | player.CharacterAdded:Connect( function () |
05 | if game.MarketplaceService:PlayerOwnsAsset(player, 11528871 ) then |
06 | player.Character:FindFirstChild(player.BackpackItem.Value):Destroy() |
07 | player.Character.Humanoid:AddAccessory(newItem) |
08 | player.BackpackItem.Value = newItem.Name |
09 | capacityEvent:FireClient(player, newItem.Capacity.Value) |
10 | end |
11 | end ) |
12 | end ) |
You need to use UserOwnsGamePassAsync
to detect when someone have a gamepass:
01 | local newItem = game.ReplicatedStorage:FindFirstChild( "InfBag" ):Clone() |
02 | capacityEvent = game.ReplicatedStorage:WaitForChild( "UICapacityEvent" ) |
03 | game.Players.PlayerAdded:Connect( function (player) |
04 | player.CharacterAdded:Connect( function () |
05 | if game.MarketplaceService:UserOwnsGamePassAsync(player.UserId, 11528871 ) then |
06 | player.Character:FindFirstChild(player.BackpackItem.Value):Destroy() |
07 | player.Character.Humanoid:AddAccessory(newItem) |
08 | player.BackpackItem.Value = newItem.Name |
09 | capacityEvent:FireClient(player, newItem.Capacity.Value) |
10 | end |
11 | end ) |
12 | end ) |