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 3 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.

local newItem = game.ReplicatedStorage:FindFirstChild("InfBag"):Clone()
capacityEvent = game.ReplicatedStorage:WaitForChild("UICapacityEvent")
game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function()
        if game.MarketplaceService:PlayerOwnsAsset(player,11528871) then
            player.Character:FindFirstChild(player.BackpackItem.Value):Destroy()
            player.Character.Humanoid:AddAccessory(newItem)
            player.BackpackItem.Value = newItem.Name
            capacityEvent:FireClient(player, newItem.Capacity.Value)
        end
    end)
end)

1 answer

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

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

local newItem = game.ReplicatedStorage:FindFirstChild("InfBag"):Clone()
capacityEvent = game.ReplicatedStorage:WaitForChild("UICapacityEvent")
game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function()
        if game.MarketplaceService:UserOwnsGamePassAsync(player.UserId,11528871) then
            player.Character:FindFirstChild(player.BackpackItem.Value):Destroy()
            player.Character.Humanoid:AddAccessory(newItem)
            player.BackpackItem.Value = newItem.Name
            capacityEvent:FireClient(player, newItem.Capacity.Value)
        end
    end)
end)
Ad

Answer this question