Hello everyone, I found a datastore script:
local DataStoreService = game:GetService("DataStoreService")
local statStore = DataStoreService:GetDataStore("StatStore")
game.Players.PlayerAdded:Connect(function(Player)
local leaderstats = Instance.new("Folder", Player)
leaderstats.Name = "leaderstats"
local cashs = Instance.new("IntValue", leaderstats)
cashs.Name = "Money"
cashs.Value = 2000
local death = Instance.new("IntValue", leaderstats)
death.Name = "Death"
death.Value = 5
local recieved, NotRecieved = pcall(function()
stat = statStore:GetAsync("UserId-"..Player.UserId)
end)
if recieved then
cashs.Value = stat[1]
death.Value = stat[2]
print("Stat was recieved")
else
print("Stat wasn't recieved")
end
while true do wait(30)
statStore:SetAsync("UserId"..Player.UserId, {cashs.Value, death.Value})
end
end)
game.Players.PlayerRemoving:Connect(function(Player)
local leaderstats = Player.leaderstats
local money = leaderstats.Money
local death = leaderstats.Death
local saved, notSaved = pcall(function()
statStore:SetAsync("UserId-"..Player.UserId, {money.Value, death.Value})
end)
if saved then
print("Stat was saved")
else
print("Stat wasn't saved")
end
end)
With this datastore script, how can I use the data saved in other scripts, for example, I want to display the value of the money and death saved in a text label. How to do this? PS: I'm a beginner
