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

UserOwnsGamePassAsync working for one user but not another? roblox's end?

basically i'm testing out my game and one account owns all the gamepasses and everything works fine. another account owns every gamepass as well and none of them work. is this a glitch on robloxs ends?

this code is basically what I have dumbed down.

game.Players.PlayerAdded:Connect(function(plr)

	plr.CharacterAdded:connect(function(char)
	 
	      if 					game:GetService("MarketplaceService"):UserOwnsGamePassAsync(game.Players[char.Name].UserId, id) then
	        print("has gamepass")
end 
end 
end

3 comments

0

those "end" s should be "end)" .. not sure if thats causing the proble, maybe the script is only listening once?

0

use end end) end) not end end end

0

theres no error in the script. that was a example

2 answers

When you have most functions that use something like :Connect , it always has to use a different type of end, written like this:

something:Connect(function()

end)

and not like this

something:Connect(function()

end

So for your code you would need to:

game.Players.PlayerAdded:Connect(function(plr)

    plr.CharacterAdded:Connect(function(char)

        if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(game.Players[plr.Name], id) then -- you also dont need to use the userid, and it would be better if you used plr.Name
            print("has gamepass")
end 
end 
end

But also, you do not state what id is. So you would need to do this:

local id = 69420

game.Players.PlayerAdded:Connect(function(plr)

    plr.CharacterAdded:Connect(function(char)

        if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(game.Players[plr.Name], id) then -- you also dont need to use the userid, and it would be better if you used plr.Name
            print("has gamepass")
end 
end 
end

I do get these type of issues, when the script is in workspace and not in ServerScriptService. Is your script is in ServerScriptService?

If no, put it in ServerScriptService.

If yes,

local id = 12345678

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function()
		if game:GetService("MarketPlaceService"):UserOwnsGamePassAsync(player.UserId, id) then
			print("Has gamepass!")
		end
	end)
end)	

Try using the code above.

Lemme know if it helps!

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