Making a tool point twards closest player

i am trying to make a part welded to a tool, look twards/point twards the direction of the closest player character, i have been trying for hours, i have tried literaly everything, can someone please explain how to make this work

while task.wait(1) do
	if equipped then
		local closest = nil
		local cloesestdistance = nil
		for _, player in pairs(game.Players:GetPlayers()) do
			local character = player.Character
			if plr and plr.Character and plr.Character:FindFirstChild("Torso") and character and plr.Name ~= player.Name then
				local distance = player:DistanceFromCharacter(plr.Character.Torso.Position)
				if not cloesestdistance or cloesestdistance > distance then 
					closest = player
					cloesestdistance = distance 
				end
			end
		end
		if closest and closest.Character and closest.Character:FindFirstChild("Torso") and plr and plr.Character and plr.Character:FindFirstChild("Torso") then 
			local pivot = script.Parent.Handle.pointer:GetPivot()
			local lookAtCFrame = CFrame.lookAt(pivot.Position, closest.Character.Torso.Position)
			local rotatedCFrame = lookAtCFrame * CFrame.Angles(0, math.pi, 0)
			--script.Parent.Handle.pointer.CFrame = CFrame.lookAt(script.Parent.Handle.pointer.Position, closest.Character.Torso.Position)
			print(rotatedCFrame)
			script.Parent.Handle.Weld.C1 = script.Parent.Handle.Weld.Part1.CFrame:ToObjectSpace(lookAtCFrame)
			--script.Parent.Handle.Weld.C1 = rotatedCFrame
		end
	end
end
1 Like

ye ik theres usless code in there, i just dont even know wth hell to do at this point, i have tried everything, im actualy done

the part welded continuously changes its rotation for no flipping reason, even though nothing changesz AGHAGAGHAGHAGHAGHAGHAGH im done

Well the problem is your not using the direction the player is facing

direction the player is facing doesnt matter, and doesnt/wouldnt affect the code im trying to make

all im tryna do is make the part face twards a diff part, no matter the look direction or wtv of the player idk how that would corrolate to anything but yee

could you show a video to see the issue clearer

yeee, basicly i have a tool, its the roblox geo locator gear, i added a part unanchored and cantcollide, welded to the gears handle, im trying to make the part face twards the closest player

i cant rlly say what the issue is, as ive tried everything, stuff that works for everyone else that for some reason doesnt work, i really dont know

i cant take videos sry, but basicly the part even tho the same 2 values get inputed, the tools position and the closest players position, it rotates completly randomly for no reason even tho the same 2 numbers get inputed idek im done with roblox rn

ig its aparently impossible to get a welded part to point twards the closest player, thats kinda crazy 21 years in the making and you cant do smthn so simple

it isnt impossible but have you tried tweaking the rotation applied to the tool

Actually why do you need the cframe.angles when your lookatcframe is already rotated

its quite hard without a video showing this kinda problem though

and theres multiple things there because ive tried everything 100 times 100 diff ways each and got lazy taking stuff out and adding it back or changing it so ye its kinda messy but im just lf someone that knows how to make a welded part face closest player since aparently its forbiden knowledge

ye i get that but, its like ur answers arnt corlating at all with anything at all lol

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