How to rotate part which direction the player humanoidrootpart look?

Script:

local Tool = script.Parent

local Event = Tool.Event

local TweenService = game:GetService("TweenService")

Event.OnServerEvent:Connect(function(Player,MousePos,Dist,MouseLookVector)

local Info = TweenInfo.new(Dist/200)

local DragonH = game:GetService("ReplicatedStorage").DragonH:Clone()

local DragonPart = game:GetService("ReplicatedStorage").DragonPart:Clone()

DragonH.Parent = game.Workspace.DragonDebris

DragonPart.Parent = game.Workspace.DragonDebris

DragonH.CFrame = (Player.Character.HumanoidRootPart.CFrame + Player.Character.HumanoidRootPart.CFrame.LookVector * 13)

DragonH.CFrame = CFrame.lookAt(DragonH.Position,MousePos)

local Goal = {}

Goal.Position = MousePos

TweenService:Create(DragonH,Info,Goal):Play()

end)

Local Script:

local Tool = script.Parent
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local Deb = false
Tool.Activated:Connect(function()
	local Event = Tool.Event
	local Distance = (Player.Character.HumanoidRootPart.Position - Mouse.Hit.Position).magnitude
	if Distance < 999 then
		if Deb == false then
			Deb = true
			Event:FireServer(Mouse.Hit.Position,Distance)
			wait(4)
			Deb = false
		end
	end
end)

The problem at this string:
DragonH.CFrame = CFrame.lookAt(DragonH.Position,MousePos)
does not return to where the player is looking

DragonH.Orientation = HumanoidRootPart.Orientation - Vector3.new(0,180,0)

So you want the parts position to stay the same but change its rotation depending on where the player is looking?

ok so, if you want to make the part look towards where the player is looking, you want to change the MousePos variable to DragonH.Position + HumanoidRootPart.CFrame.LookVector. If you want to orient the part towards the mousepos, you can do this by changing the line Event:FireServer(Mouse.Hit.Position,Distance)
to
Event:FireServer(Mouse.UnitRay.Direction,Distance)
and then changing the part of the script that actually orients the part to
DragonH.CFrame = CFrame.lookAt(DragonH.Position,MousePos+DragonH.Position)

1 Like