How to make a click to move, but on npcs?

Also, how do you make an custom animation for when your doing :MoveTo()?

Oh no, one last error.
The first unit you click is the only one that moves.
If you click another one, the first unit is thinking that you clicked it when you actually clicked the 2nd unit.

game.ReplicatedStorage.MoveEvent.OnServerEvent:Connect(function(plr, mousepos)
   local Dummy = workspace.Dummy
   local animid = "rbxassetid://ANIMIDHERE"
   local hum = Dummy.Humanoid
   local anim = Instance.new("Animation")
   anim.AnimationId = animid

   local loadedanim = hum:LoadAnimation(anim)
   hum:MoveTo(mousepos)
   loadedanim:Play()
   hum.MoveToFinished:Wait()
   loadedanim:Stop()
end)

Change ANIMIDHERE to your animation id

Change the local script to

local mouse = game.Players.LocalPlayer:GetMouse()
local db = false
local cooldown = 1
local selected = nil

mouse.Button1Down:Connect(function()
   if db == true then
      return
   end
   if selected ~= nil then
      game.ReplicatedStorage.MoveEvent:FireServer(mouse.Hit.p, selected)
      selected = nil
      db = true
      wait(cooldown)
      db = false
   else
      --make sure its a dummy and not a player
      if mouse.Target.Parent.FindFirstChild("Humanoid") and not game.Players:FindFirstChild(mouse.Target.Name) then
         selected = mouse.Target.Parent
      end
   end
end)

and the server script to

game.ReplicatedStorage.MoveEvent.OnServerEvent:Connect(function(plr, mousepos, selected)
   local Dummy = selected
   local animid = "rbxassetid://ANIMIDHERE"
   local hum = Dummy.Humanoid
   local anim = Instance.new("Animation")
   anim.AnimationId = animid

   local loadedanim = hum:LoadAnimation(anim)
   hum:MoveTo(mousepos)
   loadedanim:Play()
   hum.MoveToFinished:Wait()
   loadedanim:Stop()
end)
1 Like

Sorry for late response, i’m about to test this. It works!

1 Like

I tried this, and it didn’t work. I think I’m not putting the server script in the right place. Where do I put it?