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!
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)