I have this script here, but I only want the character to move depending on the distance from the mouse.
while wait() do
local mouse = game.Players.LocalPlayer:GetMouse()
local position = mouse.Hit.p
game.Players.LocalPlayer.Character.Humanoid:MoveTo(position)
end
It works, but I only want it to happen at a certain distance.
What I mean is, not when clicked, but the the mouse distance because the mouse is always on the screen and the character will always move, but when the mouse is near enough to the character it will stop moving, I hope that is more understandable, if not I’ll try again.
You can use magnitude to do this. Also you should be using renderstepped over while wait() do.
local RunService = game:GetService("RunService")
local Player = game:GetService("Players").LocalPlayer
local Mouse = Player:GetMouse()
RunService.RenderStepped:Connect(function(dt)
if (Player.Character.PrimaryPart.Position - Mouse.Hit.p).Magnitude >= 10 then --change 10 to the minimum distance (in studs)
--move player to mouse.hit.p
end
end)