Hey, i’m looking to make a part look at me.
Problem
I already have the script, but there is a problem with it.
When I go under the part, it’s also rotating the X and Z axis.
And I only want to rotate the Y axis.
Script
Code
--// FUNCTION
local function FindPlayer(position)
local torso = nil
local distance = 1000
local child = workspace:GetChildren()
for i=1, #child do
if child[i].className == "Model" then
local humanoid = child[i]:findFirstChild("Humanoid")
if humanoid ~= nil then
local head = child[i]:findFirstChild("Head")
if head ~= nil then
if (head.Position - position).magnitude < distance then
torso = head
head = (head.Position - position).magnitude
end
end
end
end
end
return torso
end
----------------------------------------------------------------------------------------
--// FUNCTION CALLS
game:GetService("RunService").Stepped:Connect(function()
local torso = FindPlayer(script.Parent.Position)
if torso ~= nil then
script.Parent.CFrame = CFrame.new(script.Parent.Position, torso.Position)
end
end)
Video
So how can I make it only rotate Y axis using that script ?
Thanks!