I just want to make a script where a gui is visible when a player owns a gamepass. Also my game is filtering enabled and this is a local script.
local id = 4894476 local player = game.Players.LocalPlayer if game:GetService("MarketplaceService"):PlayerOwnsAsset(player, id) then script.Parent.Visible = true else script.Parent.Visible = false end
Can someone please help me figure out what is wrong?
Thank you.
PlayerOwnsAsset
doesn't work for Gamepasses; use UserOwnsGamepassAsync
.
Heres a better script made by my friend Vissequ with your variables inserted into it:
local MarketplaceService = game:GetService("MarketplaceService") local Players = game:GetService("Players") local gamePassID = 4894476-- Change this to your game pass ID function onPlayerSpawned(player) local hasPass = false -- Check if the player already owns the game pass local success, message = pcall(function() hasPass = MarketplaceService:UserOwnsGamePassAsync(player.userId, gamePassID) print("Has Game Pass") end) -- If there's an error, issue a warning and exit the function if not success then warn("Error while checking if player has pass: " .. tostring(message)) return end if hasPass == true then script.Parent.Visible = true else script.Parent.Visible = false end end game.Players.PlayerAdded:Connect(function(player) player.CharacterAdded:Connect(function() onPlayerSpawned(player) end) end) -- Connect 'PlayerAdded' events to the 'onPlayerAdded()' function Players.PlayerAdded:Connect(onPlayerSpawned) --Script made by Vissequ