I have been trying to program a zombie that attacks your cloned character in a characters folder, but when I tested it out, the zombies seemed to be attacking my character clone from pretty far away but when I went into server view, they were way closer than it looked in the client view. Here’s my script:
local bestDistance = nil
local target = nil
local CharactersFolder = game.Workspace.Characters
local Pathfinding = game:GetService("PathfindingService")
local Debounce = false
local touch = false
script.Parent:WaitForChild("HitRadious").Touched:Connect(function(part)
--touch = true
local hum = part.Parent:FindFirstChild("Humanoid")
if hum and Debounce == false then
if hum.Health > 0 and hum.Parent.Name ~= "Zombie" then
touch = true
Debounce = true
--hum:TakeDamage(script.Parent.Damage.Value)
--hum.WalkSpeed = 0
script.Parent.HumanoidRootPart.Anchored = true
--hum:TakeDamage(10)
script.Parent.Humanoid:LoadAnimation(script.Parent.Attack):Play()
wait(0.75)
Debounce = false
if not(script.Parent.Humanoid.Health <= 0) then
script.Parent.HumanoidRootPart.Anchored = false
end
end
end
end)
script.Parent.HitRadious.TouchEnded:Connect(function(part)
if part.Parent:FindFirstChild("Humanoid") then
touch = false
end
end)
while true do
target = nil
bestDistance = nil
for i,v in pairs(CharactersFolder:GetChildren()) do
local magnitude = (v:WaitForChild("HumanoidRootPart").Position-script.Parent.HumanoidRootPart.Position).Magnitude
if magnitude < script.Parent.Range.Value and not(v.Humanoid.Health <= 0) then
if bestDistance then
if magnitude < bestDistance then
bestDistance = magnitude
target = v
end
else
bestDistance = magnitude
target = v
end
end
end
if target then
local path = Pathfinding:CreatePath()
path:ComputeAsync(script.Parent.HumanoidRootPart.Position,target.HumanoidRootPart.Position)
local waypoints = path:GetWaypoints()
for i, waypoint in pairs(waypoints) do
script.Parent.Humanoid:MoveTo(waypoint.Position)
if waypoint.Action == Enum.PathWaypointAction.Jump then
script.Parent.Humanoid.Jump = true
end
script.Parent.Humanoid.MoveToFinished:Wait(2)
if i == 2 then
break
end
end
else
wait()
end
end
there are no local scripts associated with the zombies. Why is this happening?