Hey, I'm working on a game, and to reset the whole game, I'm just killing everyone. It's the easiest that I could have thought of. So I have this "DamageEvent" that people take damage from.
local KillEvent = game:GetService("ReplicatedStorage").Events.DamageEvent;
local Players = game:GetService("Players")
local allPlayers = Players:getPlayers();
local localPlayer = Players.LocalPlayer
local NumberOfPlayers = #allPlayers;
for i = 1, NumberOfPlayers do
local PlayerName = allPlayers[i].Name;
if game:GetService("Workspace")[PlayerName] ~= nil then
KillEvent:FireServer(game:GetService("Workspace")[PlayerName].Humanoid, 999)
end
end
end)
When some people are not loaded in the game, they are still in the Players Service, but not in the Workspace as Model. So it results as a not Valid Member of Workspace. How can I fix this?

6 comments
Repeat
*Use repeat until to check if the player in the workspace is nil.
(Hey, that rhymed!)
@GreenGrassGamer2008 how do you mean that? Can you explain haha
Don't use LocalScripts to kill players.
Repeat wait() until workspace.player ~= nil I guess? It’s not the greatest of ideas but it might work