I have the following code in my “PlotHandler” server-script in ServerScriptService:
game:GetService("Players").PlayerRemoving:Connect(function(player)
local PlotNumberVariable = player:WaitForChild("PlotNumber").Value
local PlotsFolder = game.Workspace:WaitForChild("Plots")
local PlayersPlot = PlotsFolder:WaitForChild(PlotNumberVariable)
warn("Removing "..player.Name.."'s Plot.")
PlayersPlot:WaitForChild("Owner").Value = "" -- Reset plot owner value
task.wait(5) -- Give the DataStore script some time to save the plot
local ElementsPlacedFolder = PlayersPlot:FindFirstChild("ElementsPlaced")
ElementsPlacedFolder:ClearAllChildren() -- Remove all items in the plot
end)
What I’m wondering is if a player leaves, the task.wait(5) is there so it waits until the DataStore has collected the items on their plot and saved it. If another player leaves within those 5 seconds, will the PlayerRemoving event be ignored because it is already yielding?
I can probably avoid this with doing a coroutine but I have done that in the past and it only ran once and never again, so if possible, can anyone possibly help me with that?