How do I make the player move after mouse?

Hello DevForums! I was making a script which made the player move torwards the mouse, so I made a script for it.

Script:

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

while wait() do
		player:Move(mouse.Hit.p)
	end

This script does work, but once it moves in the position of the mouse, it will keep moving in the direction indefinitely, even when the position of the mouse changes.

1 Like

Try this:

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

while wait() do
	player.Character:MoveTo(mouse.Hit.p)
end

This makes you slide across the floor at an insane speed and does not seem to move in the player’s mouse direction.

So you want to move the player character when he clicks?

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

mouse.Button1Down:Connect(function()
	player.Character:MoveTo(mouse.Hit.p)
end)

Are you trying to make it so every time you click it moves your character to mouse position?

Not really. I am trying to make my character move to the mouse while a specific button is pressed and held down.

Maybe add an if statement at the end if input ended then

The issue here is that when I try to get it to move in the direction of the mouse, it goes there, but does not go anywhere else after going in one direction.

Are you getting any errors from the script?

No, I am not getting any errors from the output.

Maybe at the end after player:Move(Mouse.hit.p)
Put wait(.01)

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

while wait() do
player:Move(mouse.Hit.p)
wait(.01)
end

local player = game.Players.LocalPlayer


while wait() do
        local mouse = player:GetMouse()
		player:Move(mouse.Hit.p)
	end

try this

You’re probably thinking of Humanoid:MoveTo. Instead, try this code:

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

while wait() do
	local humanoid = player.Character:FindFirstChild("Humanoid")
	if humanoid and mouse.Hit then
		humanoid:MoveTo(mouse.Hit.p)
	end
end

Try this
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local UserInputService = game:GetService(“UserInputService”)
local Key = “V”
local Debounce = false
UserInputService.InputEnded:Connect(function(Input)
if Input.KeyCode == Enum.KeyCode[Key] and Debounce == false then
player.Character:SetPrimartPartCFrame(CFrame.new(mouse.Hit.p.X, mouse.Hit.p.Y, mouse.Hit.p.Z))
Debounce = true
wait(1)
Debounce = false
end
end)

you should make that into a code block, so others can easily read it

I’m new to the Dev Forum I legit got accepted just today.

1 Like

oh ok my bad then, anyways you just need three backticks at the top and bottom of the code
→ ` are backticks

oh thanks, I also noticed you are actually pretty decent at programming seeing you have solved a lot of stuff

2 Likes