Part that is suppose to look at the players head every two seconds script isn't working

I was watching alvin blox video on CFrames and he went to talking about how to rotate a part to look at a certain direction, he made a block look at another block. So i though it would be cool to mess around and make a block look at the players head, every two seconds. I wanted to tween it so it looks cooler. I got no errors from the script and nothing is really happening.

This is my script:

repeat wait() until game.Players.LocalPlayer.Character
local TweenService = game:GetService("TweenService")
local Tween = TweenService:Create(game.Workspace.Block,TweenInfo.new(0.5,Enum.EasingStyle.Sine),{CFrame = CFrame.new(game.Workspace.Block.Position, game.Workspace.PinnacleFusion.Head.Position)})
while true do
	Tween:Play()
	wait(2)
end

Here are some pictures of before i run it and after:
before:
help1.PNG
here is it after:
help2
i have a decal on it so i know the front face of the part.
so like i said: it is suppose to tween to look at my head every two seconds. It moves but thats all.

My solution

Try this:

local char = game.Players.LocalPlayer.CharacterAdded:Wait() -- don't loop, just use this

local TweenService = game:GetService("TweenService")
local Tween = TweenService:Create(workspace.Block,
    TweenInfo.new(0.5,Enum.EasingStyle.Sine),
    {CFrame = CFrame.lookAt(workspace.Block.Position, char:WaitForChild("Head").Position)
     -- CFrame.new(start Vector3, lookAt Vector3) is deprecated, the tutorial may have been a few years old
     -- CFrame.lookAt(start Vector3, lookAt Vector3) is what you're suppose to use
 })

while true do
	Tween:Play()
	wait(2)
end

@XdJackyboiiXd21 's solution may work

1 Like

It is because you define the tween with the original characters CFrame, not the current one. For example if you spawn at the point (10, 3, 20), the part will keep looking at that position even after you move away from that spot.To fix this, just redefine the tween inside fo the loop.

repeat wait() until game.Players.LocalPlayer.Character
local TweenService = game:GetService("TweenService")
while true do
    local Tween = TweenService:Create(game.Workspace.Block,TweenInfo.new(0.5,Enum.EasingStyle.Sine),{CFrame = CFrame.new(game.Workspace.Block.Position, game.Workspace.PinnacleFusion.Head.Position)})
	Tween:Play()
	wait(2)
end
2 Likes

that script looks way better then mine but it does the same thing

thanks it works perfectly, now i know!

1 Like