How to make a part (thats welded to something) face a player

I have a script that’s able to spin a cube around inside an NPC that shoots out raycasts it isn’t that effect since it kind of acts like a submarine sonar but I want to change this so the part looks directly at the player on the Y-axis instead of just spinning around stupidly

I’ve tried many different ways to achieve this but it hasn’t worked out well and it just either moves the NPC with it too or just doesn’t work at all. If anyone can assist me on what to do to solve this it would be great

here’s the script that works that spins the cube around the raycast stuff is in a separate one:

local tpart = script.Parent.Parent.Head
local cfpart = script.Parent
local NewNumber = 0
local w = Instance.new("Weld",tpart) 
w.Part0 = tpart 
w.Part1 = cfpart 
local cf0 = tpart.CFrame 

w.C0 = cf0:Inverse() 

while task.wait(0.001) do
	NewNumber -= 5
	local cf1 = CFrame.new(-9872.459, 21060.545, -770.799) * CFrame.Angles(0, math.rad(NewNumber), 0)
	w.C1 = cf1:Inverse() 
end
1 Like

ok nvm i just figured it out lol it was really easy

local tpart = script.Parent.Parent.Head
local cfpart = script.Parent
local w = Instance.new("Weld",tpart) 
local player = game:GetService("Players")
w.Part0 = tpart
w.Part1 = cfpart
local cf0 = tpart.CFrame 

w.C0 = cf0:Inverse() 

while task.wait(0.001) do
	local allCharaters = game.Workspace:GetDescendants()
	for _, eachCharater in pairs(allCharaters) do
		if eachCharater:IsA("Humanoid") then
			local charater = eachCharater.Parent
			local humanoid = charater:FindFirstChild("HumanoidRootPart")
			local cf1 = CFrame.lookAt(Vector3.new(-21.626, 8, 8.455), humanoid.Position)
			w.C1 = cf1:Inverse() 
		end
	end
end
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.