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

Player has asset!? please help!

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.

3 comments

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.

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.

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.

2 answers

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.

1 comment

0

but can i chage ReBorn110103 to game.Players.LocalPlayer if its a serverscript

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)

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