How would i make a function run a certain time after the player left the game ?
This is what i have rn but it doesnt work
Client:
Players.PlayerRemoving:Connect(function(plr)
if plr == player then
task.delay(2, ClearSpritesAfterLeave:FireServer(plr))
end
end)
Server:
ClearSpritesAfterLeave.OnServerEvent:Connect(function(_, plr)
for _, sprite in ipairs(Improvements:GetChildren()) do
if sprite:HasTag(plr.Name) and sprite:GetAttribute("Placing") == false then
sprite:Destroy() -- this code does work tho, i have used it on other functions and it works
-- that means the client doesnt work
end
end
end)
I don’t believe client scripts can run when a player leaves. Instead of calling the event after they leave, in the server just make it run the Players.PlayerRemoving function.
Players.PlayerRemoving:Connect(function(plr)
for _, sprite in ipairs(Improvements:GetChildren()) do
if sprite:HasTag(plr.Name) and sprite:GetAttribute("Placing") == false then
sprite:Destroy()
end
end
end)