#help me pls

1 messages · Page 1 of 1 (latest)

graceful glen
#

can you anyone tell me why my script only gives me the gamepass in roblox studio test but not in a public server


local Players = game:GetService("Players")
local MPS = game:GetService("MarketplaceService")
local ServerStorage = game:GetService("ServerStorage")

local PASS_ID = 1616740899
local TOOL_NAME = "FlyingCarpet"

local toolFolder = ServerStorage:WaitForChild("GamepassTools")

local function giveTool(player)
local tool = toolFolder:FindFirstChild(TOOL_NAME)
if not tool then
warn("Tool not found in GamepassTools folder:", TOOL_NAME)
return
end

local backpack = player:FindFirstChild("Backpack")
local character = player.Character

if not backpack then return end
if backpack:FindFirstChild(TOOL_NAME) or (character and character:FindFirstChild(TOOL_NAME)) then
    return
end

tool:Clone().Parent = backpack

end

-- REPEAT UNTIL USER OWNS GAMEPASS AND API RETURNS SUCCESS
local function reliableCheck(player)
while player.Parent do
local success, owns = pcall(function()
return MPS:UserOwnsGamePassAsync(player.UserId, PASS_ID)
end)

    if success then
        if owns then
            giveTool(player)
        end
        break -- stop retrying once we get a GOOD response
    end

    -- API FAILED → try again after 3 seconds
    task.wait(3)
end

end

Players.PlayerAdded:Connect(function(player)
reliableCheck(player)

-- Also check when character loads
player.CharacterAdded:Connect(function()
    task.wait(1)
    reliableCheck(player)
end)

-- Safe periodic checks every 20s in case something fails
task.spawn(function()
    while player.Parent do
        reliableCheck(player)
        task.wait(20)
    end
end)

end)

merry hedge
graceful glen
faint mesa
#

also i think you could remove this line right here:

local function reliableCheck(player)
    while player.Parent do -- <- this line (remove)
        local success, owns = pcall(function()
#

final function:

local function reliableCheck(player)
    local success, owns = pcall(function()
        return MPS:UserOwnsGamePassAsync(player.UserId, PASS_ID)
    end)

    if success then
        if owns then
            giveTool(player)
        end
    end
end