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

can someone fix my script? its a button script which makes a vip frame visible?

can someone help me with my script this script is in my gui button, it should make a gui frame visible when a plr clicks on a button but when a plr has gamepass it should make a vip frame visible else a free frame visible .

function Click()

local Players = game:GetService("Players")
local MarketPlaceService = game:GetService(MarketPlaceService")
local GamepassId = 10664855

function Click()
Players.PlayerAdded:Connect(function(Player) 
   if (MarketPlaceService:PlayerOwnsAsset(Player, GamepassId)) then
	      script.Parent.Parent.parent.vip.Visible = true else
		script.Parent.Parent.parent.freemode.Visible = true 
   end
end)
	
	script.Parent.MouseButton1Down:connect(Click)

1 comment

0

Is it working now?

1 answer

Firstly, make sure that you are using a Local script as I'm presuming that this script is in the PlayerGui.

Other than that, your code needs a bit cleaning up:

local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local MarketPlaceService = game:GetService("MarketPlaceService")
local GamepassId = 10664855

local function Click()

	if (MarketPlaceService:PlayerOwnsAsset(Player, GamepassId)) then
          script.Parent.Parent.parent.vip.Visible = true
	else
        script.Parent.Parent.parent.freemode.Visible = true 

	end

end

script.Parent.MouseButton1Down:Connect(Click)

However, :PlayerOwnsAsset() is usually used to check for items in the player's inventory. For gamepasses, it'd be better to use :UserOwnsGamePassAsync() which also returns true if the player owns it.

An example of it's use would be:

script.Parent.MouseButton1Click:Connect(function()
	if MarketplaceService:UserOwnsGamePassAsync(Player.UserId, GamepassId) then
		print("player owns the game pass!") --Vip thing here
	else
		print("player does not own the game pass") --Free thing here
	end
end)

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