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

How can you get a player to look at a part?

I've tried two ways one just CFraming the rootpart and the other using bodygyro but both don't seem to work.

Note: TroopA[3] is an table objectvalue of the players character

CFrame:

local startPosition = TroopA[3].HumanoidRootPart.Position
local targetPosition = Target.Hitbox.Position
TroopA[3].HumanoidRootPart.CFrame = CFrame.new(startPosition, targetPosition)

BodyGyro:

TroopA[3].HumanoidRootPart.BodyGyro.CFrame = CFrame.new(TroopA[3].HumanoidRootPart.Position, Target.Hitbox.Position)

2 answers

✓ Accepted answer

You should be able to do this with by tweening the player's humanoid root part to look at the part. It can be done seen here:

local lookAt = script.Parent -- Part.
local tweenService = game:GetService("TweenService")
local basicTweenInfo = TweenInfo.new(0.01) -- Tween time.

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		wait(5) -- To make sure the character is on the ground before doing this.
		
		local root = character:WaitForChild("HumanoidRootPart")

		spawn(function()
			while true do
				wait()
				tween(root)
			end
		end)
	end)
end)

function tween(part)
	local tweenGoals = {
		CFrame = CFrame.new(part.CFrame.Position, lookAt.CFrame.Position)
	}
	local createTween = tweenService:Create(part, basicTweenInfo, tweenGoals)
	createTween:Play()
end

May be a little shaky but this is only a written example.

Nvm I have stupid, if anyone else wants to know what I did just use this

local Object = Vector3.new( Target.Hitbox.Position.x, Target.Hitbox.Position.y, Target.Hitbox.Position.z )

TroopA[3].HumanoidRootPart.CFrame = CFrame.new( TroopA[3].HumanoidRootPart.Position, Object )

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