local DSS = game:GetService("DataStoreService") local Points = DSS:GetDataStore("Points")
game.Players.PlayerAdded:Connect(function(plr) local pPoints = Points:GetAsync(plr.UserId) or 10 local leaderstats = Instance.new("Folder",plr) leaderstats.Name = "leaderstats" local PointsValue = Instance.new("NumberValue") PointsValue.Name = "Points" PointsValue.Value = pPoints PointsValue.Parent = leaderstats while wait(300) do PointsValue.Value = PointsValue.Value +5 end PointsValue.Changed:connect(function(v) Points:SetAsync(plr.UserId,v) print("Points Saved!") end) end)
(I got help from a youtube video)
Also, how can I make this add points after a successful purchase?
local ID = 00000000 local MarketplaceService = game:GetService("MarketplaceService")
script.Parent.MouseButton1Click:Connect(function() MarketplaceService:PromptGamePassPurchase(game.Players.LocalPlayer,ID) end)
(Help from somewhere else)
Sorry if I'm asking too much!! All the Discord servers I'm in won't help, and I can't seem to figure it out.
I'll be answering only the title. If it were me, I'd do it like this:
local DataStoreService = game:GetService("DataStoreService") local Players = game:GetService("Players") local PointsStore = DataStoreService:GetDataStore("Points") Players.PlayerRemoving:Connect(function(player) local success, errorMessage = pcall(function() PointsStore:SetAsync(player.UserId, player.leaderstats.PointsValue.Value) end) if not success then warn(errorMessage) end end) Players.PlayerAdded:Connect(function(player) local success, points = pcall(function() return PointsStore:GetAsync(player.UserId) end) if success then local leaderstats = Instance.new("Folder", player) leaderstats.Name = "leaderstats" local pointsValue = Instance.new("NumberValue", leaderstats) pointsValue.Name = "Points" pointsValue.Value = points else local leaderstats = Instance.new("Folder", player) leaderstats.Name = "leaderstats" local pointsValue = Instance.new("NumberValue", leaderstats) pointsValue.Name = "Points" pointsValue.Value = 0 end end) while true do wait(300) for _,player in pairs(Players:GetPlayers()) do player.leaderstats.PointsValue.Value += 50 end end