Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local DataStoreService = game:GetService("DataStoreService")
- DataStore=game:GetService("DataStoreService"):GetGlobalDataStore()
- local Players = game:GetService("Players")
- PlayerStats = game.Lighting.PlayerStats
- local Stats = PlayerStats:clone()
- Class = "Warrior"
- Gold = 0
- Health = 100
- XP = 0
- PVP = false
- Level = 1
- Magic = 0
- function onPlayerAdded(player)
- local Players = game:GetService("Players")
- if player:FindFirstChild("PlayerStats")==nil then
- Stats.Parent = player
- end
- playersave1 = DataStoreService:GetDataStore(player.UserId, Gold)
- --playersave2 = DataStoreService:GetDataStore(player.UserId, "Class")
- playersave3 = DataStoreService:GetDataStore(player.UserId, Health)
- playersave4 = DataStoreService:GetDataStore(player.UserId, XP)
- playersave5 = DataStoreService:GetDataStore(player.UserId, Level)
- playersave6 = DataStoreService:GetDataStore(player.UserId, Magic)
- player:WaitForChild("PlayerStats")
- local playerstatus = player:FindFirstChild("PlayerStats")
- --playerstatus.Class.Value = playersave2
- playerstatus.Class.Value = DataStore:GetAsync(player.UserId, Class)
- playerstatus.Health.Value = DataStore:GetAsync(player.UserId, Health)
- playerstatus.XP.Value = DataStore:GetAsync(player.UserId, XP)
- playerstatus.Level.Value = DataStore:GetAsync(player.UserId, Level)
- playerstatus.Magic.Value = DataStore:GetAsync(player.UserId, Magic)
- playerstatus.Gold.Value = DataStore:GetAsync(player.UserId, Gold)
- --[[
- playerstatus.Gold.Value = playersave1
- playerstatus.Health.Value = playersave3 --or 100
- playerstatus.XP.Value = playersave4 --or 0
- playerstatus.Level.Value = playersave5-- or 1
- playerstatus.Magic.Value = playersave6 --or 0
- ]]
- print("UpdatedStats")
- print("Loading: "..player.Name.."Data")
- end
- --else
- function onPlayerRemoved(player)
- pcall(function()
- playersave1 = player.PlayerStats.Gold.Value
- playersave2 = player.PlayerStats.Class.Value
- playersave3 = player.PlayerStats.Health.Value
- playersave4 = player.PlayerStats.XP.Value
- playersave5 = player.PlayerStats.Level.Value
- playersave6 = player.PlayerStats.Magic.Value
- playersave1:SetAsync(player.UserId, Gold)
- playersave2:SetAsync(player.UserId, Class)
- playersave3:SetAsync(player.UserId, Health)
- playersave4:SetAsync(player.UserId, XP)
- playersave5:SetAsync(player.UserId, Level)
- playersave6:SetAsync(player.UserId, Magic)
- end)
- print("Saving: "..player.Name.." Data")
- end
- Players.PlayerAdded:Connect(onPlayerAdded)
- Players.PlayerRemoving:Connect(onPlayerRemoved)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement