There is indeed a smoother way to move NPCs along a map. There are two methods to do this. The first one is the best for you.
Using a Humanoid and Humanoid:MoveTo()
I apologize if I give any errors during this explanation, as I am working on learning this myself, but I understand how it mostly works.
First of all, you'd want to insert a humanoid into the NPC. This accesses Health, MaxHealth, WalkSpeed, JumpPower, etc. It is everything you would want to create an NPC. The best way to create one is to insert a rig, then adjust that rig, but with extra hard painful work, you could make a custom rig with more than R6 or R15 functions. Ensure it has a HumanoidRootPart and everything inside the humanoid is unanchored. You do not need to weld the humanoid together, but if anything is attached to it like a sword, you will need to weld it to the body part.
Then, you want to utilize the function "MoveTo()" which will move any humanoid that is able to and unanchored to a designated location. It even plays a smooth animation that either you made or Roblox gave you! MoveTo takes a vector3 value. It could also be a part's location!
Using the TweenService.
Now normally, if you just want to smoothly move a part along, you can just use part:TweenPosition(Vector3Value). However, there is a different way that it can be done by using the Tweening Service. It's hard to explain, so I will leave an example below.
game.Players.LocalPlayer.PlayerGui:WaitForChild("Dark")
local Darkness = game.Players.LocalPlayer.PlayerGui.Dark.Ness
local TweenService = game:GetService("TweenService")
local Info1 = TweenInfo.new(
1,
Enum.EasingStyle.Quad,
Enum.EasingDirection.Out,
0,
false,
1
)
local goals1 = {
Transparency = 0
}
local Vgoals = {
Volume = 0
}
local Info2 = TweenInfo.new(
1,
Enum.EasingStyle.Quad,
Enum.EasingDirection.Out,
0,
false,
1
)
local goals2 = {
Transparency = 1
}
local Debounce = false
script.Parent.MouseButton1Click:Connect(function()
if Debounce == false then
Debounce = true
workspace.Selection:Play()
local Tween1 = TweenService:Create(Darkness, Info1, goals1)
local VolTween = TweenService:Create(workspace.MainTheme, Info1, Vgoals)
VolTween:Play()
Tween1:Play()
Tween1.Completed:Wait()
workspace.MainTheme:Stop()
wait(1)
workspace.CurrentCamera.CFrame = workspace.CCC.CFrame
script.Parent.Parent.Parent.Enabled = false
game.Players.LocalPlayer.PlayerGui.CCC.Faction.Enabled = true
workspace.CCCTheme:Play()
local Tween2 = TweenService:Create(Darkness, Info2, goals2)
Tween2:Play()
Tween2.Completed:Wait()
wait(1)
Debounce = false
end
end)
Like animations, the TweenService needs to be created, then played. If you need more help, the roblox developer wiki will have more information on the tweenservice and it's values.
5 comments
Just for his sake, you should probably simplify this example down, it has a lot of things he doesn't need, and it probably will confuse him. Also I do recommend using the TweenService over moveto for npcs because its just easier to have them move and play custom animations at the same time especially if the NPCs themselves are not humanoids.
Then CFrame would probably be the best thing for you. But it would be laggy depending on the situation it's being used in, or you can decrease the wait value and movement the NPC makes per loop. This will make it look smoother while using CFrame
I wont use MoveTo() because my NPC is anchored, which is recquired for him not to get displaced by any other reason. Also the TweenService might make the speed of the NPC stable, but it still creates excessive stress on the server.
Maybe I should make the NPC invisible on serverside and the cframe loop have less cycles, while I clone its model clientside without any collidableparts and make a loop where it tweens to the serverside npc position, so the stress isnt so big for the server
That could also work, or remove the CFrame loop entirely, do that, and then move the NPC to it's desired location after that has finished.