-
What do you want to achieve? Keep it simple and clear!
So i’m making zombies which goes to player. When zombie is added for some reason it get some weird position to move and only when he got to this position he starts targeting player. As i checked it sets some random walktopoint position - What solutions have you tried so far? Did you look for solutions on the Developer Hub? I tryed checking every code connected with zombies spawn, but nothing found
Spawn Script:
if _Disabler["ZombieAttack"] == false then
local Zombie = game:GetService("ServerStorage").Zombie
local ZombieFolder = Instance.new("Folder")
ZombieFolder.Name = "ZombieFolder"
ZombieFolder.Parent = workspace
local max = 1
while time > 0 do
if #ZombieFolder:GetChildren() < max then
local Clone = Zombie:Clone()
Clone.Parent = ZombieFolder
local rand = Vector3.new(math.random(-100, 100), 0.5, math.random(-100, 100))
Clone.HumanoidRootPart.Position = rand
end
time -= 0.1
task.wait(.1)
end
ZombieFolder:Destroy()
end
return false
Action script:
local Humanoid = script.Parent.Humanoid
local Root = script.Parent.HumanoidRootPart
local Players = game:GetService("Players")
local SimplePath = require(game:GetService("ServerScriptService").SimplePath)
local Path = SimplePath.new(script.Parent)
local RunService = game:GetService("RunService")
local nearestTarget = nil
local nearestDistance = nil
local CanDamage = true
local _Debug = false
function cooldown(time)
while time > 0 do
time -= 1
task.wait(1)
end
CanDamage = true
end
function onHit(target)
if target and target.Parent and target.Parent:FindFirstChild("Humanoid") then
if CanDamage then
target.Parent.Humanoid.Health -= 15
CanDamage = false
cooldown(5)
end
end
end
function getTarget()
script.Parent.Humanoid.WalkToPoint = Vector3.new(0,0,0)
local character, dist = Path.GetNearestCharacter(script.Parent.HumanoidRootPart.Position)
nearestTarget = character
nearestDistance = dist
GeneratePath()
end
function GeneratePath()
if nearestTarget then
if _Debug == true then
Path.Visualize = true
end
Path:Run(nearestTarget.HumanoidRootPart)
end
end
getTarget()
--[[Path.Blocked:Connect(function()
if nearestTarget then
getTarget()
end
end)--]]
Path.WaypointReached:Connect(function()
if nearestTarget then
getTarget()
end
end)
Path.Error:Connect(function(errorType)
if nearestTarget then
getTarget()
end
end)
Path.Reached:Connect(function()
getTarget()
end)
Root.Touched:Connect(function(hit)
onHit(hit)
end)
For some reason it chooses this position
Edit: ok this is original position of zombie in server storage
Edit2: Also same things happen when it reach me as target it tryes to move back to this point and again get target