I'm trying to make the character move towards their mouse position, but it lags. I figured out the reason for this lag is because I'm calling the MousePos remotefunction way too much. Is there a way that I can get the player's mouse position every time the loop repeats, without causing lag?
___________________________________________________________________________
Here is the loop:
function activateBroom(player, count, maxcount, mouse) repeat wait() local mousepos = remotes.Parent.ServerToClient.MousePos:InvokeClient(player) player.Character.HumanoidRootPart.CFrame = CFrame.new(player.Character.HumanoidRootPart.CFrame.p, mousepos.p) * CFrame.new(0, 0, -1) count = count + 1 until count == maxcount end remotes.LearnedMoves.OnServerEvent:connect(activateBroom) -- didnt bother to rename the remote event yet, i was using it for a different purpose before.
Here is the localscript that handles the remotes:
local remotes = game.ReplicatedStorage:WaitForChild("Remotes"):WaitForChild("ServerToClient") function returnMousePos() return game.Players.LocalPlayer:GetMouse().Hit end remotes.MousePos.OnClientInvoke = returnMousePos