I wan’t to get the NPC to not be glitchy.
Heres a clip of the npc
local TweenService = game:GetService("TweenService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local npc = script.Parent.Dummy -- The NPC model
local humanoidRootPart = npc:FindFirstChild("HumanoidRootPart")
local humanoid = npc:FindFirstChildOfClass("Humanoid")
local walk = ReplicatedStorage.GameMechanics.Animations.WalkAnimation
local idle = ReplicatedStorage.GameMechanics.Animations.IdleAnimation
if not humanoidRootPart or not humanoid then
warn("HumanoidRootPart or Humanoid missing from NPC!")
return
end
-- Define movement points
local points = {
script.Parent:WaitForChild("Point1").Position,
script.Parent:WaitForChild("Point2").Position,
script.Parent:WaitForChild("Point3").Position
}
-- Load animations
local animator = humanoid:FindFirstChildOfClass("Animator")
local walkAnimation = walk:Clone()
local idleAnimation = idle:Clone()
local walkTrack = animator:LoadAnimation(walkAnimation)
local idleTrack = animator:LoadAnimation(idleAnimation)
local tweenInfo = TweenInfo.new(3, Enum.EasingStyle.Linear, Enum.EasingDirection.Out)
local function moveToPoint(index)
if walkTrack then walkTrack:Play() end -- Start walking animation
local goal = {Position = points[index]}
local tween = TweenService:Create(humanoidRootPart, tweenInfo, goal)
tween:Play()
tween.Completed:Wait() -- Wait until movement completes
if walkTrack then walkTrack:Stop() end -- Stop walking animation
end
while true do
moveToPoint(1) -- Move to Point 1
task.wait(1) -- Short pause
moveToPoint(2) -- Move to Point 2
if idleTrack then idleTrack:Play() end -- Play idle animation while waiting
local waitTime = math.random(10, 60) -- Random wait time
task.wait(waitTime)
if idleTrack then idleTrack:Stop() end -- Stop idle animation
moveToPoint(3) -- Move to Point 3
task.wait(1) -- Short pause
end
the black cubes are the points it moves to.