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

How to make a part facing the direction from the character to the mouse?

I want to make a skateboard spawning script that when ever you click the skateboard spawns where your mouse is, but I also want it to face the direction from my torso to the mouse. But how??

I believed that this involves in .unit and something with CFrame.new(position, position)

1 answer

✓ Accepted answer

I believe something like this might work:

local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()
mouse.Button1Up:Connect(function()
	local board = --set to skateboard part
	local direction = (mouse.Hit.p-plr.Character.HumanoidRootPart.Position).unit
	direction = direction * Vector3.new(1,0,1) --keep line if you only want rotation on y axis
	board.CFrame = CFrame.new(mouse.Hit.p,mouse.Hit.p + direction)
end)	

Keep in mind if the game is FilteringEnabled you will have to use RemoteEvents to create the skateboard.

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