Pathfinding issues i have no idea how to fix (still very unsolved)

Here are my issues:

  • Network ownership seems to be reverted back to normal like if i didn’t change anything, so the ownership changes to client and server (it’s singleplayer)
  • Pathfinding feels way too smooth, like it takes a while to turn which makes it easy to juke and it just looks odd
  • It sometimes just stops if it tried getting through a gap it should be able to go through, moving to the other side fixes it
  • Even though the script is disabled on start, the script will still fire the remote, making the text appear and an error appear (the scripts of the chapter are cloned and the old ones are deleted to fully restarts them)
  • And if you go downstairs (the stairs are pretty narrow but they seemed to work before) humanoid:MoveTo(waypoints[waypointindex].Position) errors with “Attempt to index nil with ‘Position’”
    sorry for all the trouble lol
    here’s the code:
local anim = script.Parent.Humanoid:LoadAnimation(script.Parent.Stun)
anim:Play()
task.wait(25)
anim:Stop()
game.ReplicatedStorage.Awaken:FireAllClients()
local pfs = game:GetService("PathfindingService")
local pathparams = {
	["AgentHeight"] = 6,
	["AgentRadius"] = 0.7,
	["AgentCanJump"] = true,
	["AgentCanClimb"] = false,
	["WaypointSpacing"] = math.huge
}
local waypoints = {}
local waypointindex = 1
local torso = script.Parent:WaitForChild("Torso")
local humanoid = script.Parent:WaitForChild("Humanoid")
local root = script.Parent:WaitForChild("HumanoidRootPart")
local anim = script.Parent.JumpscareAnimation
local animation = humanoid:LoadAnimation(anim)
local plrhumanoid
for _, plr in pairs(game.Players:GetPlayers()) do
	plrhumanoid = plr.Character.HumanoidRootPart
	script.Parent.PrimaryPart:SetNetworkOwner(plr)
end
root.Touched:Connect(function(hit)
	local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
	if plr then
		for _, parts in pairs (plr.Character:GetChildren()) do
			if not parts:IsA("Humanoid") and parts.Name ~= "HumanoidRootPart" then
				parts:Destroy()
			end
		end
		plr.Character:WaitForChild("Humanoid"):TakeDamage(100)
		root.CanTouch = false
		humanoid.WalkSpeed = 0
		plrhumanoid.Anchored = true
		plrhumanoid.Parent.Humanoid.WalkSpeed = 0
		script.Parent.Camera1.Anchored = true
		game.ReplicatedStorage.CameraFall:FireAllClients(script.Parent)
		game.ReplicatedStorage.PlayJumpscare.OnServerEvent:Connect(function()
			script.Parent.HumanoidRootPart.Jumpscare:Play()
			script.Parent.HumanoidRootPart.UneasyUrgency:Stop()
			animation:Play()
			task.delay(0.5, function()
				root.HitSound:Play()
				task.wait(0.5)
				root.HitSound:Play()
				task.wait(0.4)
				root.HitSound:Play()
			end)
		end)
		animation.Stopped:Connect(function()
			game.ReplicatedStorage.CameraFall2:FireAllClients(script.Parent)
		end)
	end
end)
local path
local function Walk()
	if plrhumanoid == nil then
		return
	end
	path = pfs:CreatePath(pathparams)
	path:ComputeAsync(torso.Position, plrhumanoid.Position)
	local waypoints = path:GetWaypoints()
	waypointindex = 2
	humanoid:MoveTo(waypoints[waypointindex].Position)
end
task.spawn(function()
	while task.wait() do
		Walk()
	end
end)
  1. Network Ownership: It seems like you’re setting the network ownership of script.Parent.PrimaryPart to the client. However, you’re doing this for all players in the game, which may cause unexpected behavior. Consider setting the network ownership only for the specific player you intend.

  2. Pathfinding Smoothness and Gap Navigation: If the pathfinding feels too smooth or the character stops when it should be able to navigate through a gap, you can adjust the AgentRadius parameter in the pathparams table. Increasing the agent radius may help the character navigate narrow spaces more effectively.

  3. Error with “Attempt to index nil with ‘Position’”: This error occurs when the waypoints table does not have a valid waypoint at the specified waypointindex. Make sure that the waypoints table is populated correctly before attempting to access a specific waypoint. Double-check that the pathfinding computation is successful and that the waypoints table is being populated as expected.

  4. Script Execution on Start: If you want to disable script execution on start, you can wrap the code in a function and call it when needed, rather than having it run automatically when the script starts. This way, you have more control over when the script should be ran.

the game is singleplayer so i am just getting the only player

already did, i’ll try to see if lowering or increasing works

could you give me code for your third point? i don’t really know how to implement that lol

there’d be too many scripts that connect since these are scripts for an entire map