Why is this not working?

Hi! I want to check if someone has owned a gamepass. This is when a button is clicked in a ScreenGui.

I’ve tried this:

MainFrame.KMAR.Join.MouseButton1Click:Connect(function(plr)
	KMAR:FireServer(plr)
	MainFrame.Visible = false
	script.Parent.Parent.Parent.Main.Visible = true

	if MarketplaceService:UserOwnsGamePassAsync(plr.UserId, KMARPass) then
		print("Yes")
	else
		print("No")
	end
end)

The error:

Players.QuantumSeaz.PlayerGui.MainUI.Screens.Teams.Handler:18: attempt to index nil with 'UserId'

I also tried this:

MainFrame.KMAR.Join.MouseButton1Click:Connect(function(plr)
	KMAR:FireServer(plr)
	MainFrame.Visible = false
	script.Parent.Parent.Parent.Main.Visible = true

	if MarketplaceService:UserOwnsGamePassAsync(plr, KMARPass) then
		print("Yes")
	else
		print("No")
	end
end)

But the error says:

Argument 1 missing or nil
2 Likes

try this:

local Players = game:GetService("Players");
local MarketplaceService = game:GetService("MarketplaceService");

MainFrame.KMAR.Join.MouseButton1Click:Connect(function()
	KMAR:FireServer();
	MainFrame.Visible = false;
	script.Parent.Parent.Parent.Main.Visible = true;

	if MarketplaceService:UserOwnsGamePassAsync(Players.LocalPlayer.UserId, KMARPass) then
		print("Yes")
	else
		print("No")
	end
end)
2 Likes

It worked! Thank you very much!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.