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

When players buy my gamepasses nothing happens?

Recently I got several people asking why their gamepasses weren't working in my game. At the time, I just assumed that the pass purchase hadn't gone through yet, so I simply told them to wait. But after a few days, none of them still had the passes. I checked the simple pass script I had and noticed the output throwing tons of warnings that consisted mainly of GamePassId [id here] is not of type Game Pass. Please use MarketplaceService:PlayerOwnsAsset instead.

So I tried using that instead, which was even worse and returned false every single time I used it.

I'm not sure how to fix this.

My extremely inefficient code is written below:

local Players = game:GetService("Players")
local repStorage = game:GetService("ReplicatedStorage")

function giveTool(tool, startGear)
	local newTool = tool:Clone()
	newTool.Parent = startGear
end

Players.PlayerAdded:Connect(function(plr)
	local starterGear = plr:WaitForChild("StarterGear")
	if game:GetService("GamePassService"):PlayerHasPass(plr, 4351689) then
		giveTool(repStorage:WaitForChild("ToolStorage"):WaitForChild("IT'S JUST AN EGG"), starterGear)
	end
	if game:GetService("GamePassService"):PlayerHasPass(plr, 4382733) then
		giveTool(repStorage:WaitForChild("ToolStorage"):WaitForChild("Protest Sign"), starterGear)
	end
	if game:GetService("GamePassService"):PlayerHasPass(plr, 4351698) then
		for i=1, 10 do
			local q = repStorage:WaitForChild("ToolStorage"):WaitForChild("Quarter"):Clone()
			q.Parent = starterGear
			game:GetService("Debris"):AddItem(q, 1)
		end
		for i=1, 75 do
			giveTool(repStorage:WaitForChild("ToolStorage"):WaitForChild("Quarter"), starterGear)
		end
		if game:GetService("GamePassService"):PlayerHasPass(plr, 4351704) then
			giveTool(repStorage:WaitForChild("ToolStorage"):WaitForChild("Lemonade Stand"), starterGear)
		end
	end
end)

It is a server script, is in ServerScriptService, and is not disabled.

3 answers

Gamepasses take time to go through. If you buy a gamepass ingame (or buy a gamepass and immediately join a game) it usually doesn't work. Give it time. Plus, try reformatting your code. Always works for me.

1 comment

0

I did all of the above.

I think you can only check if they have the gamepass using a local script. Try converting it into a local script, and place it in StarterPlayerScripts under the StarterPlayer folder.

2 comments

0

No need for PlayerAdded if you place it in StarterPlayerScripts

0

I tried this, it didn't affect anything. Same results, same warnings.

The problem's fixed. Apparently, I have to use game:GetService("MarketplaceService"):UserOwnsGamePassAsync().

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