I suggest using DataStoreService. Create a Script inside ServerScriptService and the code should be looking like this:
local DSS = game:GetService("DataStoreService")
local DS = DSS:GetDataStore("GamePassOwners")
local function create(plr)
local userId = plr.UserId
local key = "Player_" .. userId
local value = Instance.new("BoolValue", plr)
value.Name = "HasGamePassOn"
local ls = Instance.new("Folder", plr)
ls.Name = "leaderstats"
local money = Instance.new("IntValue", ls)
money.Name = "Money"
local data
local success, result = pcall(function()
data = DS:GetAsync(userId)
end)
if success and data then
value.Value = data[1] or false
money.Value = data[2] or 0
else
print("ERROR!" .. result)
end
end
local function save(plr)
local userId = plr.UserId
local key = "Player_" .. userId
local tableToSave = {
plr.HasGamePassOn.Value,
plr.leaderstats.Money.Value
}
local success, result = pcall(function()
DS:SetAsync(userId, tableToSave)
end)
if success then
print("Saved!")
else
print("Error")
warn(result)
end
end
game.Players.PlayerAdded:Connect(create)
game.Players.PlayerRemoving:Connect(save)
game:BindToClose(function()
if game:GetService("RunService"):IsStudio() then return end
for _, plr in pairs(game.Players:GetPlayers) do
save(plr)
end
end)
Then in the gamepass script, it should be like this:
local mps = game:GetService("MarketplaceService")
local plr = game.Players.LocalPlayer
local id = 0000000
script.Parent.MouseButton1Click:Connect(function()
if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(plr.UserID, id) then
if plr.HasGamePassOn.Value == false then
print("Player owns gamepass.")
local points = plr:FindFirstChild("leaderstats")
local money = points:FindFirstChild("Money")
money.Value = money.Value + 1
plr.HasGamePassOn.Value = true
else
print("You already clicked.")
end
else
mps:PromptPurchase(plr, id)
end
end)
If there are errors or mistakes, please let me know! ^^