End of Topic, new topic

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.

1 Like

I’m not sure what you’re asking for. Can you phrase it differently? Do you mean something like “Walk to where the player clicked”

1 Like

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.

1 Like

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)
2 Likes

I’m not totally sure why it isn’t working, I have tried that script but there seems to be an error with it.

1 Like

This isn’t the full script, you have to add in your movement code where I’ve left a comment.

1 Like

I have done that, but something to do with “=>” which seems to be creating the error.

1 Like

My bad, it is meant to be >=. I’ve edited my original post.

1 Like

Ah, it works now, thank you for you help.

1 Like