Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I make a block follow the player's mouse?

I have remotely no idea how to do this. I tried

foundBlock.Position = Vector3.new(mouse.Hit.p)

but it didn't work.

1 answer

✓ Accepted answer

You're actually very close.

First thing you have to do, is make sure you're using a Local Script.

-- Local Script

Now you have to make sure the Local Script is placed somewhere where it can run. I'll be using the StarterPack.

-- Local Script In StarterPack
You could also you StarterGui, and other places as well. It really doesn't matter as long as the local script isn't in Workspace or ServerScriptService.

Now get the player and the mouse,

-- Local Script In StarterPack
local plr = game.Players.LocalPlayer
local Mouse = plr:GetMouse()

Let's also define our brick at we want to follow the mouse,

-- Local Script In StarterPack
local plr = game.Players.LocalPlayer
local Mouse = plr:GetMouse()
local Brick = workspace:WaitForChild("Brick")

I'll be using a mouse move event instead of a loop because it's more efficient and less choppy.

-- Local Script In StarterPack
local plr = game.Players.LocalPlayer
local Mouse = plr:GetMouse()
local Brick = workspace:WaitForChild("Brick")

Mouse.Move:connect:function()
	--Do stuff later
end)

Now we can use Mouse.Hit to get the CFrame of the mouse in the 3d world and set it to the brick's CFrame.

-- Local Script In StarterPack
local plr = game.Players.LocalPlayer
local Mouse = plr:GetMouse()
local Brick = workspace:WaitForChild("Brick")

Mouse.Move:connect:function()
	Brick.CFrame = Mouse.Hit
end)

I hope that helps you!

Good Luck!

If I did help you, don't forget to accept my answer!

This discussion is preserved as it was. New answers, comments, and votes are closed.