local datatsoresevrice = game:GetService("DataStoreService")
local maydatastore = datatsoresevrice:GetDataStore("mydatastore")
game.Players.PlayerAdded:Connect(function(player)
local leadstats = Instance.new("Folder")
leadstats.Name ="leaderstats"
leadstats.Parent = player
local money = Instance.new("IntValue")
money.Name = "Cash"
money.Parent = leadstats
local data
local done,dailed = pcall(function()
data = maydatastore:GetAsync(player.Iserid.."-Cash")
if done then
money.Value = data
else
print("there is a error")
end
end)
end)
game.Players.PlayerRemoving:Connect(function(player)
maydatastore:SetAsync(player.UserId.."-Cash",player.leaderstats.Value)
end)
✓ ANSWER ACCEPTED
keeps say it a part for the folder but it is idk why my data store wont work, how do i fix?
1 answer
✓ Accepted answer
1° - In line 24, you put "leaderstats.Value" and how leaderstats is a folder he don't have a value. 2° - In Line, 13 you put "player.Iserid" and it would be "player.UserId". 3° - The data store script must be would this:
-- I tested and it works fine
local datatsoresevrice = game:GetService("DataStoreService")
local maydatastore = datatsoresevrice:GetDataStore("mydatastore")
game.Players.PlayerAdded:Connect(function(player)
local leadstats = Instance.new("Folder")
leadstats.Name ="leaderstats"
leadstats.Parent = player
local money = Instance.new("IntValue")
money.Name = "Cash"
money.Parent = leadstats
local data
data = maydatastore:GetAsync(player.UserId.."-Cash")
money.Value = data
end)
game.Players.PlayerRemoving:Connect(function(player)
maydatastore:SetAsync(player.UserId.."-Cash",player.leaderstats.Cash.Value)
end)
This discussion is preserved as it was. New answers, comments, and votes are closed.
