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)