Hi guys. Today I have realized that my game works perfectly when tested in local file, or without actual use of some systems like data stores, but when I decided to test game on live server, I got some problems:
Argument 1 missing or nil
IDK why this errors occurs, and why coroutine wrap causes it, I think I did everything fine. Can someone please help me find my mistake?
local function SaveData(Player, PlayerLeft, Immediate, Subject)
if string.match(Subject, "Inventory") then
PlayersData[Player].Inventory:Save(PlayerLeft, Immediate)
end
if string.match(Subject, "Island") then
PlayersData[Player].Island:Save(PlayerLeft, Immediate)
end
end
for _, Player in ipairs(Players:GetPlayers()) do
coroutine.wrap(LoadData)(Player) -- similar example where coroutine works.
end
local function ServerShutdown()
--code
end
Players.PlayerAdded:Connect(LoadData)
Players.PlayerRemoving:Connect(function(Player)
warn(Player)
coroutine.wrap(SaveData)(Player, true, false, "InventoryIsland")
--error location #1
end)
game:BindToClose(ServerShutdown)
coroutine.wrap(function() --this works
while true do
task.wait(300)
for _, Player in ipairs(Players:GetPlayers()) do
warn(Player)
coroutine.wrap(SaveData)(Player, false, false, "InventoryIsland")
--but this doesn't, same error, #2
end
end
end)()