I have a zombie script that was working before but seems to not work anymore due to this error. Here is the code
function findNearestTorso(pos)
local list = game.Workspace:GetChildren()
local torso = nil
local dist = 30
local temp = nil
local human = nil
local temp2 = nil
local zombie = nil
for x = 1, #list do
temp2 = list[x]
if (temp2.className == "Model") and (temp2 ~= Zombie) then
temp = temp2:findFirstChild("HumanoidRootPart") -- Checks for HumanoidRootPart
human = temp2:findFirstChild("Humanoid") -- Checks for Humanoid
zombie = temp2:findFirstChild("ZombieCheck") -- Triple checks for a IntValue named "ZombieCheck"
if (temp ~= nil) and (human ~= nil) and (human.Health > 0) and not zombie then -- If it has a HumanoidRootPart, A humanoid and doesnt have a ZombieCheck IntValue then
if (temp.Position - pos).magnitude < dist then
torso = temp
dist = (temp.Position - pos).magnitude
end
end
end
end
return torso
end
You aren’t firing anything alongside player, so pos will be nil.
Also, why aren’t you just using CharacterAdded on the player in the server script to prevent unnecessary network traffic?
How would I use characteradded in the serverscript to fire the event everytime a character is added.
and how would I set it out to have pos along with player