I am trying to make a script where a humanoid wanders around and when you get close to the humanoid they will chase you until you reset or get killed by the humanoid.
here is what I have so far:
local CurrentPart = nil
local MaxInc = 60
function onTouched(hit)
if hit.Parent == nil then
return
end
local humanoid = hit.Parent:findFirstChild("humanoid")
if humanoid == nil then
CurrentPart = hit
end
end
function waitForChild(parent, childName)
local child = parent:findFirstChild(childName)
if child then
return child
end
while true do
print(childName)
child = parent.ChildAdded:wait()
if child.Name==childName then
return child
end
end
end
local Figure = script.Parent
local Humanoid = waitForChild(Figure, "humanoid")
local Torso = waitForChild(Figure, "HumanoidRootPart")
local Left = waitForChild(Figure, "LeftFoot")
local Right = waitForChild(Figure, "RightFoot")
Humanoid.Jump = true
Left.Touched:connect(onTouched)
Right.Touched:connect(onTouched)
while true do
wait(math.random(2, 6))
if CurrentPart ~= nil then
if math.random(5, 7) == 1 then
Humanoid.Jump = true
end
Humanoid:MoveTo(Torso.Position + Vector3.new(math.random(-MaxInc, MaxInc), 0, math.random(-MaxInc, MaxInc)), CurrentPart)
end
end
If someone can successfully finish the script for me I will pay them with robux. Thanks |