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

Gamepass only GrapgicalUserInterface not showing up with no errors?

So I am new at lua and was figuring out how to make a gui for gamepass owners only. This is my script, no errors but it's not working (note that it was a studio test.)

wait(1) 
gamepassid = 7106056
MPS = game:GetService("MarketplaceService")
function respawned(char)
local player = game.Players:FindFirstChild(char.Name)
if char:FindFirstChild("Head") ~= nil then
if MPS:UserOwnsGamePassAsync(player.UserId, gamepassid) then
print"Player has Gamepass"
script.Parent.Visible = true
end
else
print"Player does not have gamepass."
end
end
game.Workspace.ChildAdded:connect(respawned)


And it's annoying because the title made me do stuff and I didn't want to type the actual meaning of GUI.

1 answer

✓ Accepted answer

So, you should use Local Script inside GUI's, first of all, the best way is to use Local Player since it's the Local Script so you can get Local Player from Players service.

local GamepassID = 7106056-- ID of your gamepass

local Player = game:GetService("Players").LocalPlayer

local MarketplaceService = game:GetService("MarketplaceService")

game.Players.PlayerAdded:Connect(function() -- Runs a function when player joined.
	if MarketplaceService:UserOwnsGamePassAsync(Player.UserId, GamepassID) then -- Checks if player has the gamepass
		print("Player owns a gamepass!")
		script.Parent.Visible = true
	else
		print("Player doesn't have the Gamepass")
	end
end)

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