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.
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
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)