Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by 7 years ago

I have a localscript in StarterGui with the following code.

01local passId = 900915415
02 
03function authenticate(player)
04    return game:GetService("GamePassService"):PlayerHasPass(player, passId)
05end
06 
07game.Players.PlayerAdded:Connect(function()
08    if authenticate(game.Players.LocalPlayer.Character.Name) then
09        game.Players.LocalPlayer.PlayerGui.PremiumShop.Enabled = true
10        game.Players.LocalPlayer.PlayerGui.Shop.Enabled = false
11    else
12        game.Players.LocalPlayer.PlayerGui.PremiumShop.Enabled = false
13        game.Players.LocalPlayer.PlayerGui.Shop.Enabled = true
14    end
15end)

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

Log in to vote
0
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
7 years ago
Edited 7 years ago

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:

1local ms = game:GetService("MarketplaceService")
2local passId = 900915415
3local gui = script.Parent --This is your GUI
4 
5gui.Visible = ms:PlayerOwnsAsset(game.Players.LocalPlayer,passId)
1
Thanks! I used gui.Enabled instead because of screen guis. Draebrewop 114 — 7y
Ad

Answer this question