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