Make rig walk to mouse

Basically, im trying to make it so whenever i click somewhere, the Rig walks to it.

Localscript in StarterPlayerScripts
Ive tried, but it dosent seem to work.

local Players = game:GetService("Players")
local player = Players.LocalPlayer
local mouse = player:GetMouse()
local soldier = game.Workspace:WaitForChild("Soldier")
mouse.Button1Down:Connect(function()
	if mouse.Target then
		local hitPosition = mouse.Hit.p 
		soldier.Humanoid:MoveTo(hitPosition)
	end
end)

I also keep getting an error, and dont know what it means.

observableValue undefined
1 Like

Theres many ways to go about this (first 2 are VERY unconventional, i advise going with the third way)

  • Setting the Network Ownership of a part in Soldier to the player (through a server script) so that the Player (not LocalPlayer) owns the physics
workspace.Soldier.PrimaryPart:SetNetworkOwner(PlayerHere)
  • Making the Soldier clientside (if for whatever reason you need it to be clientside)
    You can do it by putting the soldier in ReplicatedStorage and using :Clone() on it

  • Using RemoteEvents to communicate to the server that you want to move the soldier

The error is a current bug in studio, it seems that everyone is getting it

Also your code is clientsided, the main issue is that you are trying to move the Soldier (which by default the Server is handling the physics of the Soldier, not the LocalPlayer)

I would use the LocalScript to communicate with a Script using RemoteEvent to send information of the mouse position

1 Like

You need to move the rig on the server or it won’t work. Since its not possible to access the mouse on the server, we need to use RemoteEvents to communicate between server and client. You can look at the post above for the documentation.

-- Script in local script..
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local mouse = player:GetMouse()
local rigmoveevent = game.ReplicatedStorage.RigMoveEvent
mouse.Button1Down:Connect(function()
   if not mouse.Target then return end
   rigmoveevent:FireServer(mouse.Hit.p)
end)
-- Script in server script in server script service..
local rigmoveevent = game.ReplicatedStorage.RigMoveEvent
local soldier = workspace.Soldier
rigmoveevent.OnServerEvent:Connect(function(plr,pos)
   soldier.Humanoid:MoveTo(pos)
   soldier.Humanoid.MoveToFinished:Wait() -- Optional statement
end)
1 Like

There is a setting in the default player controller, assuming your rig is the default character:

CLICK_TO_MOVE = Enum.DevComputerMovementMode.ClickToMove
StarterPlayer.DevComputerMovementMode = CLICK_TO_MOVE

You can also change that setting from the explorer by going to StarterPlayer.

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