local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Lighting = game:GetService("Lighting")
local Players = game:GetService("Players")
local Teams = game:GetService("Teams")
if rng == 1 then
game.Workspace:WaitForChild("ZombieSound"):Play()
local zombiesky = ReplicatedStorage:WaitForChild("RedSky"):Clone()
Lighting:ClearAllChildren()
zombiesky.Parent = Lighting
game.Workspace:WaitForChild("zombiestart"):Play()
for i, v in pairs(Players:GetPlayers()) do
if v.Team == Teams.Zombies then
local inventory = v.Backpack
for i,h in pairs(inventory:GetChildren()) do
if h:IsA("Tool") then
h:Destroy()
end
end
for i, h in pairs(v.Character:GetChildren()) do
if h:IsA("Tool") then
h:Destroy()
end
end
task.wait(1.6)
local zombiestuff = ReplicatedStorage:WaitForChild("ZombieStuff")
local zombiehead = zombiestuff:WaitForChild("ZombieHead"):Clone()
local zombieyell = zombiestuff:WaitForChild("zombiesound"):Clone()
local clawtool = zombiestuff:WaitForChild("Claw"):Clone()
clawtool.Parent = v.Backpack
zombieyell.Parent = v.Character
zombiehead.Parent = v.Character:WaitForChild("Head")
if v.Character:FindFirstChildOfClass("Shirt") then
v.Character:FindFirstChildOfClass("Shirt"):Destroy()
end
if v.Character:FindFirstChildOfClass("Pants") then
v.Character:WaitForChild("Pants"):Destroy()
end
task.spawn(function()
local shirt = Instance.new("Shirt")
shirt.ShirtTemplate = "rbxassetid://15947510"
shirt.Parent = v.Character
local pant = Instance.new("Pants")
pant.PantsTemplate = "rbxassetid://7156230"
pant.Parent = v.Character
end)
spawn(function()
for i,b in pairs(zombiestuff:WaitForChild("ZombieMeshes"):GetChildren()) do
local zombiemesh = b:Clone()
zombiemesh.Parent = v.Character
end
while true do
task.wait(3)
zombieyell:Play()
end
end)
pcall(function()
v.Character:WaitForChild("IsZombie").Value = true
v.Character:WaitForChild("Humanoid").Health = v.Character:WaitForChild("Humanoid").Health + 50
v.Character:WaitForChild("ACS_Client"):WaitForChild("Stances"):WaitForChild("Mobility").Value += 5
end)
end
end
end
local Lighting = game:GetService("Lighting")
local Players = game:GetService("Players")
local Teams = game:GetService("Teams")
local rng = math.random(1,1)
if rng == 1 then
game.Workspace:WaitForChild("ZombieSound"):Play()
local zombiesky = ReplicatedStorage:WaitForChild("RedSky"):Clone()
Lighting:ClearAllChildren()
zombiesky.Parent = Lighting
game.Workspace:WaitForChild("zombiestart"):Play()
for i, v in pairs(Players:GetPlayers()) do
if v.Team == Teams.Zombies then
local inventory = v.Backpack
for i,h in pairs(inventory:GetChildren()) do
if h:IsA("Tool") then
h:Destroy()
end
end
for i, h in pairs(v.Character:GetChildren()) do
if h:IsA("Tool") then
h:Destroy()
end
end
task.wait(1.6)
local zombiestuff = ReplicatedStorage:WaitForChild("ZombieStuff")
local zombiehead = zombiestuff:WaitForChild("ZombieHead"):Clone()
local zombieyell = zombiestuff:WaitForChild("zombiesound"):Clone()
local clawtool = zombiestuff:WaitForChild("Claw"):Clone()
clawtool.Parent = v.Backpack
zombieyell.Parent = v.Character
zombiehead.Parent = v.Character:WaitForChild("Head")
if v.Character:FindFirstChildOfClass("Shirt") then
v.Character:FindFirstChildOfClass("Shirt"):Destroy()
end
if v.Character:FindFirstChildOfClass("Pants") then
v.Character:WaitForChild("Pants"):Destroy()
end
task.spawn(function()
local shirt = Instance.new("Shirt")
shirt.ShirtTemplate = "rbxassetid://15947510"
shirt.Parent = v.Character
local pant = Instance.new("Pants")
pant.PantsTemplate = "rbxassetid://7156230"
pant.Parent = v.Character
end)
spawn(function()
for i,b in pairs(zombiestuff:WaitForChild("ZombieMeshes"):GetChildren()) do
local zombiemesh = b:Clone()
zombiemesh.Parent = v.Character
end
while true do
task.wait(3)
zombieyell:Play()
end
end)
pcall(function()
v.Character:WaitForChild("IsZombie").Value = true
v.Character:WaitForChild("Humanoid").Health = v.Character:WaitForChild("Humanoid").Health + 50
v.Character:WaitForChild("ACS_Client"):WaitForChild("Stances"):WaitForChild("Mobility").Value += 5
end)
end
end
end```
You don’t even need :FindFirstChild. Use dot operator. If something that should be there (like ZombieStuff folder) isn’t there, error will tell you right away where the problem is.
I cleaned the code from waitforchild as much as I can. Hopefully it will help to unserstand where it is okay to use and where it isn’t.
But the problem, however, is not really in this code. If it is a servers-side code, it will run before client is even connected, even in studio.
Try to add game:GetService("Players").PlayerAdded:Wait() before rng check.
If this code runs mid-game it shouldn’t be a problem, but in this specific case it may be.
local RepStorage = game:GetService("ReplicatedStorage")
local Lighting = game:GetService("Lighting")
local ZombieStuff = RepStorage.ZombieStuff
local WorkspaceZombieSound = workspace.ZombieSound
local Zombiestart = workspace.zombiestart
local ZombieSkyOrig = RepStorage.RedSky
local rng = math.random(1,1)
if rng == 1 then
WorkspaceZombieSound:Play()
local zombiesky = ZombieSkyOrig:Clone()
zombiesky.Parent = Lighting
Zombiestart:Play()
for i,v in pairs(game:GetService("Players"):GetPlayers()) do
print(v.Name.."'s team color is: "..tostring(v.TeamColor))
if v.TeamColor == BrickColor.new("Bright red") then
print("IT'S A ZOMBIE!!!")
local Character = v.Character
if not Character then
print("... or not. Sadly, "..v.Name.." doesn't have a character at the moment.")
continue --continue to next iteration (next player) if this one got no character
end
local Humanoid = Character:FindFirstChild("Humanoid")
if Humanoid then
Humanoid:UnequipTools()
end
-- Character's tool move to backpack instantly, we wait just for .Unequipped events to fire
game:GetService("RunService").Heartbeat:Wait()
local inventory = v.Backpack
for i,h in pairs(inventory:GetChildren()) do
if h:IsA("Tool") then
h:Destroy()
end
end
local zombiehead = ZombieStuff.ZombieHead:Clone()
zombiehead.Parent = Character:FindFirstChild("Head")
local zombieyell = ZombieStuff.zombiesound:Clone()
zombieyell.Parent = Character.PrimaryPart --needs to be paranted to a part to be directional
local clawtool = ZombieStuff.Claw:Clone()
clawtool.Parent = v.Backpack
-- Character may not have shirt, we need to check for that and if it isn't there just then continue
local shirt = Character:FindFirstChild("Shirt")
if shirt then
shirt:Destroy()
end
local pants = Character:FindFirstChild("Pants")
if pants then
pants:Destroy()
end
task.spawn(function()
-- not sure if it's even working
local shirt = Instance.new("Shirt")
shirt.ShirtTemplate = "rbxassetid://15947510"
shirt.Parent = Character
local pant = Instance.new("Pants")
pant.PantsTemplate = "rbxassetid://7156230"
pant.Parent = Character
end)
task.spawn(function()
for i,b in pairs(ZombieStuff.ZombieMeshes:GetChildren()) do
-- won't work either
local zombiemesh = b:Clone()
zombiemesh.Parent = Character
end
while true do
task.wait(3)
zombieyell:Play()
end
end)
Character:WaitForChild("IsZombie").Value = true
Character:WaitForChild("Humanoid").Health = v.Character:WaitForChild("Humanoid").Health + 50
Character:WaitForChild("ACS_Client"):WaitForChild("Stances"):WaitForChild("Mobility").Value += 5
end
end
end
All it does is just forces script to wait until there is a player, with a character, in a zombie team.
Without this check whole script was executing before there is even a single character that is eliglible for zombiefication.
So if you instead just run your code every N seconds then you don’t need it at all.