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)
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)