Why is my brick rotating the wrong way?


Goal

I’m currently working on a person tracking/following spotlight feature, the goal is to have it where I can reset it when I need to.

Error

My error is that when I run the script to make it follow; it doesn’t turn from the correct angle. Click on me to see the example. The glowing side is what has the light and that’s the side I need to face the player.

Script

while true do
	wait(.05)
	if game.Workspace:FindFirstChild("Just2Terrify") and game.Workspace["Just2Terrify"]:FindFirstChild("Head") then
		script.Parent:SetPrimaryPartCFrame(CFrame.new(script.Parent.PrimaryPart.Position,game.Workspace.Just2Terrify.Head.Position))
	end
end

1 Like

You can add an additional 90 degree offset on the Y axis to the goal CFrame (might be -90, try it if it’s facing away from the player). Also, use :PivotTo(), :SetPrimaryPartCFrame will cause the parts to drift away over time.

local goal = CFrame.new(script.Parent.PrimaryPart.Position,workspace.Just2Terrify.Head.Position)
goal *= CFrame.Angles(0,math.rad(90),0) -- angles requires the argument to be in radians so use math.rad() for degrees to radians
script.Parent:PivotTo(goal)
2 Likes