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.

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

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:

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
Thanks! I used gui.Enabled instead because of screen guis. Draebrewop 114 — 7y
Ad

Answer this question