So recently I bought a trails gamepass system to use for my game but every so often it errors. Here is the code:
local function playerJoin(plr)
local gamepasses = Instance.new("Folder")
gamepasses.Name = "gpInfo"
gamepasses.Parent = plr
for gamepassId, name in pairs(gamepassInfo) do
if gamepassId <= 0 then return end
if MarketplaceService:UserOwnsGamePassAsync(plr.UserId, gamepassId) then
createValue(name, gamepasses)
end
end
plr.CharacterAdded:Connect(function(chr)
local hrp = chr:WaitForChild("HumanoidRootPart")
chrAttachments[plr] = nil
if chrTrails[plr] then
wearTrail(plr, hrp)
end
end)
end
and heres the error:
Script: Workspace.Trails.Trail_Gamepasses Message: InternalServerError Trace: Workspace.Trails.Trail_Gamepasses, line 147 - function playerJoin
Workspace.Trails.Trail_Gamepasses, line 171
the error occurs on the line that uses UserOwnsGamepassAsync. I’ve seen some other posts about this but they don’t really have a sure solution. They say to wrap it in a pcall, but that doesn’t really solve the issue because if it errors then the player cant use their gamepass. How would bigger games fix this issue?
You do need to wrap it in a pcall and handle it accordingly. If the request fails, try again after a minute or so.
You could also just save the pass ownership to their general data when you go to save it, this could act as a sort of cache but you would still need to check ownership for passes that aren’t found in the cache.
honestly im not sure i didnt make the script and i cant really understand it i can post the whole script here tho
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local Workspace = game:GetService("Workspace")
local TweenService = game:GetService("TweenService")
local TRAILS = script.Parent
local TWEEN_INFO = TweenInfo.new(2, Enum.EasingStyle.Linear)
local chrTrails = {}
local chrAttachments = {}
local gamepassInfo = {}
local function createAttachment(offset, parent)
local attach = Instance.new("Attachment")
attach.Position = offset
attach.Parent = parent
return attach
end
local function wearTrail(plr, hrp)
local chrAttachment = chrAttachments[plr]
if not chrAttachment then
local hrp = plr.Character:FindFirstChild("HumanoidRootPart")
if not hrp then return end
chrAttachments[plr] = {}
chrAttachments[plr][1] = createAttachment(Vector3.new(0, 0.8, 0), hrp)
chrAttachments[plr][2] = createAttachment(Vector3.new(0, -0.8, 0), hrp)
chrAttachment = chrAttachments[plr]
end
local equippedTrail = hrp:FindFirstChildOfClass("Trail")
if equippedTrail then
equippedTrail:Destroy()
end
local trail = chrTrails[plr]:Clone()
trail.Attachment0 = chrAttachment[1]
trail.Attachment1 = chrAttachment[2]
trail.Parent = hrp
end
local function createValue(name, parent)
local value = Instance.new("IntValue")
value.Name = name
value.Parent = parent
end
--When they buy a gamepass, create a value in the gamepasses folder
MarketplaceService.PromptGamePassPurchaseFinished:Connect(function(plr, gamepassId, purchased)
if purchased then
createValue(gamepassInfo[gamepassId], plr.gpInfo)
chrTrails[plr] = TRAILS:FindFirstChild(gamepassInfo[gamepassId]).Trail
wearTrail(plr, plr.Character.HumanoidRootPart)
end
end)
--Hook up events to the trail pads
for _, trailModel in pairs(TRAILS:GetChildren()) do
local trailName = trailModel.Name
local toggle = trailModel:FindFirstChild("Toggle")
local trail = trailModel:FindFirstChild("Trail")
local gamepassId = trailModel:FindFirstChild("GamepassId") and trailModel.GamepassId.Value
if not toggle or not trail or not gamepassId then continue end
toggle.Touched:Connect(function(hit)
local chr = hit and hit.Parent
local plr = Players:GetPlayerFromCharacter(chr)
if chrTrails[plr] == trail then return end
if plr then
local plrPasses = plr.gpInfo
if plrPasses:FindFirstChild(trailName) then
chrTrails[plr] = trail
wearTrail(plr, chr:FindFirstChild("HumanoidRootPart"))
else
if gamepassId <= 0 then return end
MarketplaceService:PromptGamePassPurchase(plr, gamepassId)
end
end
end)
end
--Load the gamepass info and configure the pads
for _, trailModel in pairs(TRAILS:GetChildren()) do
local billboardGui = trailModel:FindFirstChild("ProductInfo")
local gamepassId = trailModel:FindFirstChild("GamepassId") and trailModel.GamepassId.Value
if not gamepassId then continue end
local gamepassCost
local succ, err = pcall(function()
gamepassCost = MarketplaceService:GetProductInfo(gamepassId, Enum.InfoType.GamePass).PriceInRobux
end)
if not succ then
warn("THE GAMEPASS ID IS INCORRECT")
end
local colourPlatform = trailModel.Morph
local manualCustomization = trailModel:FindFirstChild("ManualCustomization") and trailModel.ManualCustomization.Value
local trail = trailModel.Trail
if gamepassId then
gamepassInfo[gamepassId] = trailModel.Name
end
if not manualCustomization then
if billboardGui then
local priceLabel = billboardGui.Price
local nameLabel = billboardGui.ItemName
nameLabel.Text = string.upper(trailModel.Name)
nameLabel.UIGradient.Color = trail.Color
if not gamepassCost then
priceLabel.TextColor3 = Color3.fromRGB(0, 0, 0)
priceLabel.TextStrokeColor3 = Color3.fromRGB(255, 255, 255)
priceLabel.Text = "offsale"
else
priceLabel.Text = gamepassCost.." robux"
end
end
local colourSequence = trail.Color.Keypoints
colourPlatform.Color = colourSequence[1].Value
end
end
local function playerJoin(plr)
local gamepasses = Instance.new("Folder")
gamepasses.Name = "gpInfo"
gamepasses.Parent = plr
for gamepassId, name in pairs(gamepassInfo) do
if gamepassId <= 0 then return end
if MarketplaceService:UserOwnsGamePassAsync(plr.UserId, gamepassId) then
createValue(name, gamepasses)
end
end
plr.CharacterAdded:Connect(function(chr)
local hrp = chr:WaitForChild("HumanoidRootPart")
chrAttachments[plr] = nil
if chrTrails[plr] then
wearTrail(plr, hrp)
end
end)
end
--Set up gamepass folder and give the trail on respawn
for _, plr in ipairs(Players:GetPlayers()) do
playerJoin(plr)
end
Players.PlayerAdded:Connect(function(plr)
playerJoin(plr)
end)
--Remove player references on leave
Players.PlayerRemoving:Connect(function(plr)
chrAttachments[plr] = nil
chrTrails[plr] = nil
end)
print(gamepassInfo)
So I assumed right, so your playerjoin(plr) function does is it is looping through the table and checking if the values you putted in the table is owned by the player but here there aren’t IDs in the table. Go to gamepassInfo and add gamepass IDs.