-
What do you want to achieve?
I’m currently trying to create a tower defense like game via a tutorial, I’ve gotten the enemy movement down. The enemies SHOULD walk to each waypoint until it reaches the end. There are only 2 enemies, the Noob and the Heafty. -
What is the issue?
The Heafty bypasses waypoint 5 and goes off path. It’s strange and I don’t know a fix!
-
What solutions have you tried so far?
I haven’t tried much, couldn’t find anyone else with the problem.
Module script that manages movement, animations, etc.
local ServerStorage = game:GetService("ServerStorage")
local PhysicsService = game:GetService("PhysicsService")
local mob = {}
function mob.Move(entityName, map, animationName)
local humanoid = entityName:WaitForChild("Humanoid")
local waypoints = map.waypoints
local normalWalk = game.ReplicatedStorage[animationName]
for waypoint=1, #waypoints:GetChildren() do
humanoid:MoveTo(waypoints[waypoint].Position)
local loaded = humanoid:LoadAnimation(normalWalk)
loaded.Looped = true
loaded:Play()
humanoid.MoveToFinished:Wait()
loaded:Stop()
end
entityName:Destroy()
end
function mob.spawnEntity(entityName, amnt, map, animationName)
local mobExists = ServerStorage.entities:FindFirstChild(entityName)
if mobExists then
for i=1, amnt do
wait(0.5)
-- Drag the mob selected into the workspace.
local newMob = mobExists:Clone()
newMob.HumanoidRootPart.CFrame = map.Path.ENTRANCE["Spawn-Brick"].CFrame
newMob.Parent = workspace.ExistingMobs
newMob.HumanoidRootPart:SetNetworkOwner(nil)
for i, object in ipairs(newMob:GetDescendants()) do
if object:IsA("BasePart") then
PhysicsService:SetPartCollisionGroup(object, "Mob")
end
end
coroutine.wrap(mob.Move)(newMob, map, animationName)
end
else
warn("Could not grab entitiy --> ", entityName)
end
end
return mob
Main script that uses the module script
local mob = require(script.Mob)
local map = workspace["Seemless Plains"]
for wave=1,10 do
print("Wave is starting -->", wave)
if wave <= 2 then
mob.spawnEntity("Noob", 4, map,"normals-static")
elseif wave >= 5 then
mob.spawnEntity("Noob", 8, map,"normals-static")
elseif wave <=7 then
mob.spawnEntity("Heafty", 2, map, "normals-static")
mob.spawnEntity("Noob", 4, map,"normals-static")
elseif wave == 10 then
mob.spawnEntity("Heafty", 5, map, "normals-static")
end
repeat
task.wait(5)
until #workspace.ExistingMobs:GetChildren() == 0
end
If there are any other detail I can provide then please, let me know! I’ll respond whenever I’m free, thank you!