So, this test script here makes my character look at a block:
local MyPart = script.Parent
local player
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Wait()
player = plr
end)
repeat wait() until player ~= nil
local char = player.Character
local root = char.HumanoidRootPart
while wait() do
root.CFrame = CFrame.lookAt(root.Position, Vector3.new(MyPart.Position.X, root.Position.Y, MyPart.Position.Z))
end
IT WORKS. but my character keeps teleporting back to their spot, so i cant move.
any advice?
the Position of the HumanoidRootPart never changes, only the CFrame does. Also, in a server script, this wouldn’t be smooth at all. Use a local script inside of StarterGui.
local lookpart = --reference part
local RS = game:GetService("RunService")
local plr = game.Players.LocalPlayer
RS.RenderStepped:Connect(function()
if plr.Character and plr.Character:FindFirstChild("HumanoidRootPart") then
plr.Character.HumanoidRootPart.CFrame = CFrame.new(plr.Character.HumanoidRootPart.CFrame.Position, lookpart.Position)
end
end)