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

How can I make a game pass script that gives you an accessory when you own it?

Asked by 4 years ago

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.

01local newItem = game.ReplicatedStorage:FindFirstChild("InfBag"):Clone()
02capacityEvent = game.ReplicatedStorage:WaitForChild("UICapacityEvent")
03game.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)
12end)

1 answer

Log in to vote
1
Answered by
Leamir 3138 Moderation Voter Community Moderator
4 years ago

You need to use UserOwnsGamePassAsync to detect when someone have a gamepass:

01local newItem = game.ReplicatedStorage:FindFirstChild("InfBag"):Clone()
02capacityEvent = game.ReplicatedStorage:WaitForChild("UICapacityEvent")
03game.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)
12end)
Ad

Answer this question