Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Datastore = game:GetService("DataStoreService"):GetDataStore("plrData")
- game.Players.PlayerAdded:Connect(function(p)
- local leaderstats = Instance.new("Folder", p)
- leaderstats.Name = "leaderstats"
- local Money = Instance.new("NumberValue", leaderstats)
- Money.Name = "Money"
- Money.Value = 50
- local Knockouts = Instance.new("IntValue", leaderstats)
- Knockouts.Name = "KOs"
- local Wipeouts = Instance.new("IntValue", leaderstats)
- Wipeouts.Name = "Deaths"
- local savedData
- local success, errMsg = pcall(function()
- savedData = Datastore:GetAsync(p.UserId.."-Money")
- end)
- if success then
- p.leaderstats.Money.Value = savedData
- else
- warn(errMsg)
- end
- p.CharacterAdded:Connect(function(char)
- char.Humanoid.Died:Connect(function(killed)
- local CreatorTag = char.Humanoid:FindFirstChild("creator")
- if CreatorTag and CreatorTag.Value then
- local leaderstatsPlr = CreatorTag.Value:WaitForChild("leaderstats")
- leaderstatsPlr["Money"].Value += 20
- leaderstatsPlr["KOs"].Value += 1
- end
- end)
- end)
- end)
- game.Players.PlayerRemoving:Connect(function(p)
- local success, errMsg = pcall(function()
- Datastore:SetAsync(p.UserId.."-Money", p.leaderstats.Money.Value)
- end)
- if success then
- print(p.UserId.."'s data was successfully saved.")
- else
- warn(errMsg)
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement