How to create a DataStore with Cash (Roblox Studio Scripting Tutorial 2021)

Опубликовано: 03 Октябрь 2024
на канале: No Cap: Studio
1,728
18

Join my new discord:   / discord   Join my new roblox group: https://www.roblox.com/groups/5821166... script:
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("BoolValue", player)
leaderstats.Name = "leaderstats"
local Cash = Instance.new("IntValue", leaderstats)
Cash.Name = "Cash"
Cash.Value = 0

local DataStore = game:GetService("DataStoreService"):GetDataStore("SaveCash")
local Key = player.UserId
local Data = DataStore:GetAsync(Key)

if Data then
Cash.Value = Data
end
end)

game.Players.PlayerRemoving:Connect(function(player)
local Key = player.UserId
DataStore:SetAsync(Key,player.leaderstats.Cash.Value)
end)