Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.