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

Any idea why this playeradded script isn't working in an FE or non-FE game?

I have a localscript in StarterGui with the following code.

local passId = 900915415

function authenticate(player)
    return game:GetService("GamePassService"):PlayerHasPass(player, passId)
end

game.Players.PlayerAdded:Connect(function()
	if authenticate(game.Players.LocalPlayer.Character.Name) then
		game.Players.LocalPlayer.PlayerGui.PremiumShop.Enabled = true
		game.Players.LocalPlayer.PlayerGui.Shop.Enabled = false
	else
		game.Players.LocalPlayer.PlayerGui.PremiumShop.Enabled = false
		game.Players.LocalPlayer.PlayerGui.Shop.Enabled = true
	end
end)

There are no output errors.

I want the script to enable the premium shop if the player has the gamepass, and the normal shop if the player doesn't have the gamepass upon joining. This script doesn't work in a FE game or non-FE game. Any feedback would be appreciated, thanks!

1 answer

✓ Accepted answer

A PlayerAdded event only fires when a player enters the server.. you don't need it.

The StarterGui is already going to load whenever the client's Character spawns.. so you can simply set the UI's visibility according to if they own the pass or not.

I suggest using PlayerOwnsAsset rather than PlayerHasPass because it returns live results from the website rather than cached results from the start of the server.

Put this in the gui:

local ms = game:GetService("MarketplaceService")
local passId = 900915415
local gui = script.Parent --This is your GUI

gui.Visible = ms:PlayerOwnsAsset(game.Players.LocalPlayer,passId)

1 comment

1

Thanks! I used gui.Enabled instead because of screen guis.

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