function FindPlayer(zombie, player)
local humanoid
local radius = 100
local distance
local alerted = false
for _, character in ipairs(workspace:GetChildren()) do
print("Working")
if character:IsA("Model") and character:FindFirstChild('Humanoid') then
print("Work")
local targetPlayer = players:GetPlayerFromCharacter(character)
if targetPlayer then
distance = (zombie.Torso.Position - character.HumanoidRootPart.Position).magnitude
if distance < radius then
zombie.Zombie:MoveTo(character.HumanoidRootPart.Position)
end
end
end
end
end
Trying to script a move to player function however Im not getting any prints past this line
for _, character in ipairs(workspace:GetChildren()) do
print("Working")
Is there anything im doing wrong, also yes im using the function in another part of my script. Theres no errors being printed out
not sure but it might be: for _, v in ipairs(). ipairs was designed for an index, but since you’re using _, it wouldn’t work like that, try switching it to pairs
a few changes (minor):
function FindPlayer(zombie)
local radius = 100
local distance
for _, character in workspace:GetChildren() do
print("Working")
if character:FindFirstChild("Humanoid") then
print("Work")
local targetPlayer = players:GetPlayerFromCharacter(character)
if targetPlayer then
distance = (zombie.PrimaryPart.Position - character.PrimaryPart.Position).Magnitude
if distance < radius then
zombie:SetNetworkOwner(nil)
zombie.Zombie:MoveTo(character.PrimaryPart.Position)
end
end
end
end
end