Entire script not running

I was trying to make a pathfinding script that does not run. It is under a entity that is created by using the dungeonify module, the entity is part of one of the structures. (Dungeonify - Large templated structure generator with quotas and restrictions). It uses the simplepath module (SimplePath - Pathfinding Module). The only other script in the entire place is one that makes a custom skybox. Any help would be appreciated


while task.wait(1) do
print("started")
local npc = script.Parent -- the path to the NPC
local human = npc.Humanoid -- getting the humanoid of the npc
local ServerStorage = game:GetService("ServerStorage")
local SimplePath = require(ServerStorage.SimplePath)
local Range = 1000
for i,v in ipairs(game.Players:GetChildren()) do
	print("yes")
	if (v.Character.HumanoidRootPart.Position - npc.Sphere.Position).magnitude <= Range then
		print("got plr")
		local path = SimplePath.new(npc)
		path.Visualize = true
		path:Run(v.Character.HumanoidRootPart.Position)
		print("running")
		path.Blocked:Connect(function()
			path:Run(v.Character.HumanoidRootPart.Position)
		end)
		else
        
	end
end
end

Your issue is print("started") doesn’t print to the console right?

I took the liberty of re-writing the code for you:

if not (script.ClassName == "Script" and script.RunContext == Enum.RunContext.Legacy) then error("Script is most likely client-sided") end

local Players = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")

local RANGE = 1000

local SimplePath = require(ServerStorage.SimplePath)

local npc = script.Parent
local humanoid = npc.Humanoid

local connection

print("starting loop")

while true do
	for _, player in Players:GetPlayers() do
		if player.Character and (player.Character.PrimaryPart.Position - npc.Sphere.Position).Magnitude <= RANGE then
			print("player detected")

			local path = SimplePath.new(npc)
			path.Visualize = true
			path:Run(player.Character.PrimaryPart.Position)
			print("running")

			if connection then continue end -- To prevent rewriting the Blocked connection

			connection = path.Blocked:Once(function()
				path:Run(player.Character.PrimaryPart.Position)
				connection = nil
			end)
		end
	end

	task.wait(1)
end

Hopefully it will work, and it should be more efficient than the current code :slight_smile::+1:


I’ve added a line of code to help with debugging, if need be

I found the issue. Because dungeonify runs on a local script normally, the server script didn’t work. Thanks for the help anyways

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