Recently I sponsored my game for 10k to find as many bugs as possible, and I found a bug that's way worse than I wanted to find. When a script is doing something to a player and they leave in that millisecond while that is happening, it breaks the script, therefore breaking the whole game. I added things like "if v" (v being the player) before every line that interacts with the player (v), but it still breaks sometimes. How would I stop this from happening?
A little bit of the code:
function TeleportZombies()
local ZombiesLeft = 0
for i,v in pairs(players:GetPlayers()) do
if v then
if v:FindFirstChild("Human") and v:FindFirstChild("IsPlaying") and v:FindFirstChild("TypeOfZombie") and v then
if v.IsPlaying.Value == true and v then
if v.Human.Value == false and v then
ZombiesLeft = ZombiesLeft + 1
rs.RoundInformation.ZombiesLeft.Value = ZombiesLeft
if v then v.Team = teams.Zombies else return end
local TeleportModel = workspace.CurrentMap.ZombieSpawns
local num = 0
for i,v in pairs(TeleportModel:GetChildren()) do
num = num+1
end
local teleportpart = TeleportModel[math.random(1,num)].Position
if v and v.Character then v.Character:MoveTo(teleportpart) end
for i,a in pairs(ZombieWeapons:GetChildren()) do
if a.Name == v.TypeOfZombie.Value then
if v then
local bwep = a:Clone()
local swep = a:Clone()
bwep.Parent = v.Backpack
swep.Parent = v.StarterGear
end
end
end
rs.Events3.PickZombieVisible:FireClient(v)
else
--[[
for i,item in pairs(v.ItemsForNextRound:GetChildren()) do
if v then
item.Parent = v.Backpack
end
end
--]]
end
else
end
end
end
end
end

1 comment
Care to show an example script?