I just wanted to know if it would be possible if I could put these functions into one module script, or would I have to put each function into a seperate Module Script?
wait (3)
NPC = script.Parent
Children = NPC:GetChildren()
humanoid = NPC.Humanoid
IsHurt = false
SpawnPos = NPC.Spawn.Position
humanoid.Health = humanoid.Health - 5
print ("An NPC named: " ..NPC.Name.. " has been born")
function ContinueWalking()
NPC.Busy.Value = false
while NPC.Busy.Value == false do
wait (math.random(4, 6))
humanoid:MoveTo(Vector3.new(SpawnPos.X, 7.4, SpawnPos.Z) + Vector3.new(math.random(-90, 90), 0, math.random(-90, 90)), NPC.Spawn)
wait (math.random(3, 6))
humanoid:MoveTo(Vector3.new(SpawnPos.X, 7.4, SpawnPos.Z) + Vector3.new(math.random(-90, 90), 0, math.random(-90, 90)), NPC.Spawn)
end
end
function StopWalking()
NPC.Busy.Value = true
end
function RunFromDanger()
print (NPC.Name.. " is in danger!")
NPC.Busy.Value = true
IsHurt = true
walkspeed = humanoid.WalkSpeed
for i,v in pairs(Children) do
if v.className == "Tool" then
v:Destroy()
end
end
repeat
humanoid.WalkSpeed = 25
wait (.5)
humanoid:MoveTo(Vector3.new(SpawnPos.X, 7.4, SpawnPos.Z) + Vector3.new(math.random(-50, 50), 0, math.random(-50, 50)), NPC.Spawn)
wait (.5)
humanoid:MoveTo(Vector3.new(SpawnPos.X, 7.4, SpawnPos.Z) + Vector3.new(math.random(-50, 50), 0, math.random(-50, 50)), NPC.Spawn)
until humanoid.Health == humanoid.MaxHealth
humanoid.WalkSpeed = walkspeed
end
function ReturnToSpawn()
IsHurt = false
print (NPC.Name.. " is returning to spawn")
humanoid:MoveTo(Vector3.new(SpawnPos.X, 7.4, SpawnPos.Z), NPC.Spawn)
NPC.Busy.Value = false
end
function Hurt()
NPC.Busy.Value = true
if humanoid.Health > 0 and humanoid.Health < humanoid.MaxHealth and NPC.Busy.Value == true and IsHurt == false then
StopWalking()
RunFromDanger()
ReturnToSpawn()
ContinueWalking()
end
end
humanoid.HealthChanged:connect(Hurt)
