I have a piece of code, and it SHOULD enable a screengui whenever a player has a gamepass, but it's not working! Can someone please help? Code:
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local gamePassID = 4439769 -- 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
game.Players.LocalPlayer.PlayerGui.Test.Enabled = true
end
end
game.Players.PlayerAdded:connect(function(player)
player.CharacterAdded:connect(function()
onPlayerSpawned(player)
end)
end)
-- Connect 'PlayerAdded' events to the 'onPlayerAdded()' function
Players.PlayerSpawned:Connect(onPlayerSpawned)

2 comments
Anyting on output(F9)
Yeah, Its saying Playerspawned is not a member of Player, and it's saying 'Serverscriptservice.Script' line 34