Hi, I’m watching a scripting tutorial and my script isn’t working and I can’t find out what the error is. Here is the script and try to tell what’s wrong with it;
local DataStorageService = game:GetService(“DataStoreService”)
local myDataStore = DataStorageService:GetDataStore(“myDataStore”)
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local Cash = Instance.new("IntValue")
Cash.Name = "Cash"
Cash.Parent = leaderstats
local playerUserId = "Player_"..player.UserId
--Load Data
local data
local succes, errormessage = pcall(function()
data = myDataStore:GetAsync(playerUserId)
end)
if succes then
Cash.Value = data
--Setdata to the current cash
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local playerUserId = “Player_”…player.UserId
local data = player.leaderstats.Cash.Value
local success, errormessage = pcall(function()
myDataStore:SetAsync(playerUserId, data)
end)
if success then
print("Data successfully saved!")
else
print("error im gonna cry")
warn(errormessage)
end
There’s also a way to store lots of data in one key, instead of using like 500 keys. If you want to store lots of data at once, you can use Tables | Roblox Creator Documentation. There are also more ways that are more efficient, that you can search for, but this is just to give you a good start.