So my script should only give this box if you have the gamepass but for somereason it will give the box and promt if you dont have to gamepass does anyone know the problem?
system = script.Parent
model = system.Box --
backup = model:Clone()
regen = system.Regen
local gamepassId = 148181594
local market = game:GetService("MarketplaceService")
local function checkRegen(plr)
if regen.Value == 1 then
if market:UserOwnsGamePassAsync(plr.UserId,gamepassId) then
wait(1)
model = backup:Clone()
model.Parent = system
model:MakeJoints()
else
market:PromptGamePassPurchase(plr, gamepassId)
end
end
end
game.Players.PlayerAdded:Connect(function(plr)
end)
regen.Changed:Connect(function()
for i,v in next, game:GetService("Players"):GetPlayers() do
checkRegen(v)
end
end)
``
local function checkRegen(plr)
if market:UserOwnsGamePassAsync(plr.UserId, gamepassId) then
if regen.Value == 1 then
wait(1)
model = backup:Clone()
model.Parent = system
model:MakeJoints()
end
else
market:PromptGamePassPurchase(plr, gamepassId)
end
end
I would try adding a pcall and printing out the error message if there is one. If it prints out the error, tell me what it says please.
local function checkRegen(plr)
if regen.Value == 1 then
local owned
local success, errorMessage = pcall(function()
owned = market:UserOwnsGamePassAsync(plr.UserId, gamepassId)
end)
if success and owned then
task.wait(1)
model = backup:Clone()
model.Parent = system
model:MakeJoints()
else
if errorMessage then
warn(errorMessage)
elseif not owned then
warn("Player does not own the gamepass", plr.Name.." "..plr.UserId)
end
end
else
market:PromptGamePassPurchase(plr, gamepassId)
end
end
You should also call the function in the PlayerAdded event. Not necessary, but recommended, and also depending on what you want.