MarketplaceService: UserOwnsGamePassAsync() only working for one player

Hello So I made a game and I put gamepasses in it but when people spawn only I get the gamepass and when someone in my game bought the gamepass they didn’t get the item for some reason… They rejoined and everything I don’t know whats wrong.

Can someone tell me how to fix this or do I have to wait for a day and it will fix itself?

Script:

local GamepassID = 13311851
local GamepassID2 = 13340435

game.ReplicatedStorage.TeleportEvent2.OnServerEvent:Connect(function(player)
	player.Character.HumanoidRootPart.CFrame = game.Workspace.Spawn1.CFrame
	if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, GamepassID) then
		game.ServerStorage.Z80:Clone().Parent = player.Backpack
	if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, GamepassID2) then
			game.ServerStorage.Chainsaw:Clone().Parent = player.Backpack
		end
	end	
end)

Instead of relying on an event you can actually use PromptPurchaseFinished to process when a player purchases a gamepass in game. As for your bug, you should be using UserOwnsGamePassAsync whenever a player joins a game or whenever it is required to check for a gamepass. (Such as gamepass specific items in a shop or checking if a player can access something like a VIP door)

Actually the event teleports all players to the map its not for the gamepass. And people get the item when they are teleported.

So then you can check when the player joins the server in that case.

Quick note: make sure to wrap the function in a pcall, since it’s a web call.

Ok… Is there anything in these scripts I need to change for it to work?

-- ServerScript that checks if player has gamepass:

local GamepassID = 13311851
local GamepassID2 = 13340435
local GamepassID3 = 13333240

game.Players.PlayerAdded:Connect(function(player)
	local Gamepasses = Instance.new("Folder")
	Gamepasses.Parent = player
	Gamepasses.Name = "Gamepasses"

	local Chain = Instance.new("BoolValue",Gamepasses)
	Chain.Name = "ChainGun"

	local Z80 = Instance.new("BoolValue",Gamepasses)
	Z80.Name = "Z80"

	local Chainsaw = Instance.new("BoolValue",Gamepasses)
	Chainsaw.Name = "Chainsaw"

	if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId,GamepassID) then
		Z80.Value = true
	if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId,GamepassID2) then
		Chainsaw.Value = true
	if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId,GamepassID3) then
		Chain.Value = true
	end
	end
	end
end)

-- ServerScript when all players teleport to the map when they are supposed to get the weapon:

game.ReplicatedStorage.TeleportEvent2.OnServerEvent:Connect(function(player)
	player.Character.HumanoidRootPart.CFrame = game.Workspace.Spawn1.CFrame
	if player.Gamepasses.Z80.Value == true then
		game.ServerStorage.Z80:Clone().Parent = player.Backpack
	if player.Gamepasses.Chainsaw.Value == true then
			game.ServerStorage.Chainsaw:Clone().Parent = player.Backpack
		end
	end
end)

Your if statements are setup incorrectly such that for someone to be seen as having GamepassID3 they most also have GamepassID1 and GamepassID2.

	if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId,GamepassID) then
		Z80.Value = true
	end
	if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId,GamepassID2) then
		Chainsaw.Value = true
	end
	if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId,GamepassID3) then
		Chain.Value = true
	end
	end
	end

Should be:

	if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId,GamepassID) then
		Z80.Value = true
	end
	if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId,GamepassID2) then
		Chainsaw.Value = true
	end
	if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId,GamepassID3) then
		Chain.Value = true
	end

And the if statements in the OnServerEvent code have the same problem.

Thank you so much! I seriously didn’t notice that.