I have remotely no idea how to do this. I tried
foundBlock.Position = Vector3.new(mouse.Hit.p)
but it didn't work.
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
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!