Freddy is walking strange

Hey!

I’m making a FNaF fangame, now I’m making the chasing system of Freddy, but he is teleporting or stoping when walking. Can anyone help me to figure out why?

The system i made is probably a bit confusing i think, sorry :sweat_smile:

HuntModule
local HuntModule = {}

HuntModule.Stopped = true
HuntModule.Hunting = false

local stop = false
function HuntModule:Start(player)
print("StartedHunting")
	Freddy.Humanoid.WalkSpeed = 20
		
	local playerCharacter = player.Character

	local freddyPath = PathfindingService:CreatePath()
	freddyPath:ComputeAsync(Freddy.PrimaryPart.Position, playerCharacter.PrimaryPart.Position)
	local Waypoints = freddyPath:GetWaypoints()
	
	for waypointIndex, waypoint in pairs(Waypoints) do
		Freddy.Humanoid:MoveTo(waypoint.Position)
		Freddy.Humanoid.MoveToFinished:Wait()
		if waypointIndex == 5 then break end -- max waypoints before update player's position
		if (Freddy.PrimaryPart.Position - player.Character.PrimaryPart.Position).Magnitude < 3 then print("Died")return "Died" end
	end
	
	print("Finished")
end


return HuntModule

I choosed this system because it update player’s position, but I do not know if this is the best method.
In the method HuntModule:Start(), basically, Freddy take a few steps to the choosed player, and then end, to update player’s position.
This method is fired in a RunService.RenderStepped event that checks first if a variable called FreddyIsHunting == false (it is outside this module and when this method starts it is true, when end, it is false) and later if a player is seen by Freddy or is in a distance from Freddy < 30.

I warned you it was confusing lol.
If I need to give more details, tell me :grin:

(if there is any grammatic errors, sorry, english is not my native language)

Your code is very basic and has room for many issues. I recommend you read the Character Pathfinding tutorial by Roblox to get a better understanding as to why your NPC displays weird behavior.

1 Like

Oh, okay, I will read this, thank you!

1 Like

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