Hey everyone! My output is showing I have a warning (in title). I was following an AlvinBlox tutorial, as I am learning lua. Could someone help me out with this error? The code is pretty messy as well.
local DataStoreService = game:GetService("DataStoreService")
local myDataStore = DataStoreService: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 data
local success, errormessage = pcall(function()
data = myDataStore:GetAsync(Player.UserID.."-Cash")
end)
if success then
Cash.Value = data
Cash = Cash + 1
else
print("error when getting data")
warn(errormessage)
end
end)
game.Players.PlayerRemoving:Connect(function(Player)
local success, errormessage = pcall(function()
myDataStore:SetAsync(Player.UserID.."-Cash",Player.LeaderStats.Cash.Value)
end)
if success then
print("datasave completed successfully")
else
print("error when saving data, reported to owner")
warn(errormessage)
end
end)
Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.