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

Player has asset!? please help!

Asked by 8 years ago

What is wrong here? Im trying to make a gui appear when they have a gamepass?

game.Players.PlayerAdded:connect(function(plr)
    if game:GetService("MarketplaceService"):PlayerOwnsAsset(plr,408836915) then
        game.Players.LocalPlayer.PlayerGui.ScreenGui.Frame.Visible = true
    else
        game.Players.LocalPlayer.PlayerGui.ScreenGui.Frame.Visible = false
    end
end)

Im not sure that ive dont this right but i checked the wiki.

1
Is FE on? And is this in a server script? If this is in a server script with FE on, scripts can't access PlayerGui or LocalPlayer. If this is in a local script, there's no point in a Player Added function. User#11440 120 — 8y
1
you can only use game.Players.LocalPlayer in a local script. yet you can only use game:GetService("MarketplaceService"):PlayerOwnsAsset(plr,408836915) in a regular script. and game.Players.PlayerAdded:connect(function(plr) should only be used on the server. LostPast 253 — 8y
0
Is it a server script. It wont work if its a server script, and its completely fine to put this in a local script, fe doesnt really change anything and playeradded works on local scripts too. LifeInDevelopment 364 — 8y

2 answers

Log in to vote
0
Answered by 8 years ago

Well... If you need to find a gamepass, use the GamepassService, not the MarketplaceService. MarketplaceService is mainly for checking if a user has a T-Shirt, Shirt, Pants, etc. It was an "improved" way of the old way of getting VIP. Anyways, here's a function I made to check if a player has a gamepass:

function HasPass(plr, id)
    return game:GetService("GamePassService"):PlayerHasPass(plr, id)
end

--Example code:

if HasPass(game.Players.ReBorn110103, 408836915) then
    print("ReBorn110103 has gamepass ID 408836915)
end

However, both ways can only be found with a ServerScript. If you use a LocalScript, the script will error and log out that PlayerHasPass cannot be used from the client.

0
but can i chage ReBorn110103 to game.Players.LocalPlayer if its a serverscript AuthenticOakChair 68 — 8y
Ad
Log in to vote
0
Answered by 8 years ago

So thanks for answering but I ReWrote it and it works

local clone = game.Workspace.ScreenGui:Clone()
local id = 408836915

game.Players.PlayerAdded:connect(function(player)
    if game:GetService("GamePassService"):PlayerHasPass(player, id) then
        print("player has the gamepass :O")
        clone.Parent = player.PlayerGui
    else
        print("player doesn't have the gamepass :(")
    end
end)

Answer this question