local datastore = game:GetService("DataStoreService"):GetDataStore("BucksDatastore")
local defaultCash = 100
local playersLeft = 0
game.Players.PlayerAdded:Connect(function(player)
playersLeft = playersLeft + 1
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local bucks = Instance.new("IntValue")
bucks.Name = "Bucks"
bucks.Value = 0
bucks.Parent = leaderstats
player.CharacterAdded:connect(function(character)
character.Humanoid.WalkSpeed = 16
character.Humanoid.Died:Connect(function()
-- whenever somebody dies, the event will run
if character.Humanoid and character.Humanoid:FindFirstChild("creator") then
game.ReplicatedStorage.Status.Value = tostring(character.Humanoid.creator.Value).." KILLED "..player.Name
end
if character:FindFirstChild("GameTag") then
character.GameTag:Destroy()
end
player:LoadCharacter()
end)
end)
-- Data Stores
local player_data
pcall(function()
player_data = datastore:GetAsync(player.UserID.."-Bucks")
end)
if player_data ~= nil then
-- Player has saved data , load it in
bucks.Value = player_data
else
-- New Player
bucks.Value = defaultCash
end
end)
local bindableEvant = Instance.new
game.Players.PlayerRemoving:Connect(function(player)
pcall(function()
datastore:SetAsync(player.UserID.."-Bucks",player.leaderstats.Bucks.Value)
print("Saved")
playersLeft = playersLeft - 1
bindableEvant:Fire()
end)
end)
game:BindToClose(function()
-- This will be triggered upon shut down
while playersLeft > 0 do
bindableEvant.Evant:Wait()
end
end)
Closed as Not Constructive by User#24403
This question has been closed because it is not constructive to others or the asker. Most commonly, questions that are requests with no attempt from the asker to solve their problem will fall into this category.
Why was this question closed?