AI Pathfind Help

I think only the spawner but disabling the script still doesn’t fix it

local rep = game.ReplicatedStorage
local updateTimers = rep.UpdateTimers
local formatNumber = require(rep.FormatNumbers)
local enemies = game.ReplicatedStorage.Enemy:GetChildren()
local seconds = 60
local wave = 0
local spawns = workspace.Spawns:GetChildren()

local requiredBalls = 2
task.wait(2)
repeat
	task.wait(1)
if seconds ~= 0 and wave ~= 3 then
	seconds -= 1
	updateTimers:FireAllClients(formatNumber.convertToMinutesAndSeconds(seconds))
	local canSpawn = math.random(1,10)
	
	if canSpawn >= 3 then -- 70% chance to spawn
		local enemyToSpawn = enemies[math.random(1, #enemies)]
		local randomSpawnPoint = spawns[math.random(1, #spawns)]
		local enemyClone = enemyToSpawn:Clone()
		
		enemyClone.HumanoidRootPart.Position = randomSpawnPoint.Position
		enemyClone.Parent = workspace
		enemyClone.HumanoidRootPart:SetNetworkOwner()
	end
elseif seconds <= 0 then
	
	-- Next Wave Starts Here
	if workspace.Deposit.CurrentGolds.Value >= requiredBalls then
		wave +=1
	seconds = 60 -- Reset to starting value
	requiredBalls += 5
	else
		for i, v in pairs(game.Players:GetPlayers()) do
			v.Character.Humanoid.Health = 0
		end
	end
end
until wave == 3
1 Like

I tested it out with multiple NPCs at once and it still worked well, so something must be wrong in your game specifically. Try disabling the spawning script, and just insert the NPCs workspace. Let me know what happens

I do have to log off rn but I’m thinking I may have to create a new baseplate then move everything from the existing game into the new baseplate.

i’ve done both of those but it still did the same thing, its weird.

If you copy everything from the old game and paste it into the new one you may also be copying whatever is making it break.

i’m going to copy everything one at a time so I can see what specifically is making it break.

Sounds very tedious. I have a couple wild guesses I would try before that:

  1. Disable all the spawning scripts + any other script that could possibly affect the NPC
  2. Make the NPC print the target’s name
  3. See what happens if you only spawn one NPC
  4. Double check for any errors (you can use a print() statement to make sure the code is still running at a given point in time)
  5. You could also try using Humanoid:Move(), its not as good as SimplePath, but you could see if it somehow fixes your problem
1 Like

I did all the things you suggested and I found that this code works which I may use temporarily


local SSS = game:GetService("ServerScriptService")
local SimplePath = require(game.ReplicatedStorage.SimplePath)

--local module = require(game.ReplicatedStorage.AI.GetClosestPlayer)


--Define npc
local Dummy = script.Parent

--Create a new Path using the Dummy
local Path = SimplePath.new(Dummy)

--Helps to visualize the path
Path.Visualize = true

local rs = game:GetService('RunService')
rs.Heartbeat:Connect(function()
	if Dummy.Humanoid.Health >= 1 then
		local char = SimplePath.GetNearestCharacter(script.Parent.HumanoidRootPart.Position)
		Dummy.Humanoid:MoveTo(char.HumanoidRootPart.Position)
	end
end)

This other code I tried while debugging gave me two different values so it could be the issue.


local SSS = game:GetService("ServerScriptService")
local SimplePath = require(game.ReplicatedStorage.SimplePath)

--local module = require(game.ReplicatedStorage.AI.GetClosestPlayer)


--Define npc
local Dummy = script.Parent

--Create a new Path using the Dummy
local Path = SimplePath.new(Dummy)

--Helps to visualize the path
Path.Visualize = true

local rs = game:GetService('RunService')
rs.Heartbeat:Connect(function()
	if Dummy.Humanoid.Health >= 1 then
		local char = SimplePath.GetNearestCharacter(script.Parent.HumanoidRootPart.Position)
		print(Path._position)
		print( SimplePath.GetNearestCharacter(script.Parent.HumanoidRootPart.Position).HumanoidRootPart.Position)
		Path:Run(char.HumanoidRootPart)
	end
end)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.