playerremoving roblox
playerremoving roblox from Pastebin
Playerremoving roblox Pastebin
-- make sure to have a script inside of ServerScriptService.
local DataStore = game:GetService("DataStoreService"):GetDataStore("ValueSave")
game.Players.PlayerAdded:Connect(function(plr)
local leaderstats = Instance.new("Folder", plr)
leaderstats.Name = "leaderstats"
local Points = Instance.new("IntValue", leaderstats)
Points.Name = "Points"
Points.Value = DataStore:GetAsync(plr.userId) or 0
Points.Changed:Connect(function()
DataStore:SetAsync(plr.userId, Points.Value)
end)
end)
game.Players.PlayerRemoving:Connect(function(plr)
DataStore:SetAsync(plr.userId, plr.leaderstats.Points.Value)
end)
-- Credits to GaryScripts for scripting the code.