Currently, I have a bank system, but it resets everytime you join or leave the game. How would I make it that the IntValue’s Value get put into a DataStore so people can keep their money?
This is an image of the explorer when ingame:
Currently, I have a bank system, but it resets everytime you join or leave the game. How would I make it that the IntValue’s Value get put into a DataStore so people can keep their money?
This is an image of the explorer when ingame:
local DataStore = game:GetService("DataStoreService"):GetDataStore("CHANGE_THIS")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder", player)
leaderstats.Name = "leaderstats"
local Gold = Instance.new("IntValue", leaderstats) -- blah blah make your stats
-- Load data
local data
local key = "Player_".. player.UserId
local success, errormessage = pcall(function()
data = DataStore:GetAsync(key)
end)
if success then
Gold.Value = data
elseif data == nil then
Gold.Value = 0
else
warn(errormessage)
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local key = "Player_".. player.UserId
local data = player.leaderstats.Gold.Value
DataStore:SetAsync(key, data)
end)
There is already another post similar to this, but here ya go.
You should really look into DataStore2
It’ll help a lot with making DataStores