I’m making a gui that teleports the player to another place after clicking on a gui and owning a gamepass. It’s raising an error:
Error while checking if player has pass: Players.Roblozinko.PlayerGui.TeleportGui.TeleportButton.LocalScript:11: attempt to index nil with ‘UserId’ (x3)
here’s my script.
local teleportService = game:GetService("TeleportService")
local gamepassService = game:GetService("GamePassService")
local players = game:GetService("Players")
local MarketplaceService = game:GetService("MarketplaceService")
local gamepassID = 13702484
local function guiClick(player)
local hasPass = false
local success, message = pcall(function()
hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, gamepassID)
end)
if not success then
warn("Error while checking if player has pass: " .. tostring(message))
return
end
if hasPass == true then
print(player.Name .. "owns the gamepass:" .. gamepassID)
--teleport
teleportService:Teleport(6167832809, player)
else
--player does not own the gamepass
MarketplaceService:PromptGamePassPurchase(player, gamepassID)
end
end
script.Parent.MouseButton1Click:Connect(guiClick)
I mixed a couple of tutorials from Developer Hub together to see if it would work, if that helps.
Thank you for your answers.