im trying to make a part welded to a tools handle, face the closest players character, however it seems to be impossible, i cant, no one else, the internet, freaking ai cant seem to figure out why code that apparently works for everyone else doesnt work for me
this is the code, and yes there alot of random suff that shouldnt be there, ive tried everything 100 flipping times 100 differant flipping ways each and got lazy removing and readding and changing or adjusting things so ye its a little messy, im looking for someone that can ig get an idea of what i was trying to do and make my code do what i was trying to get it to freaking do, aparently its impossible to do, A.I cant figure it out, google doesnt have anything on it, and apparently no one else, but yee if u know how to it would be greatly apreciated if you could help me out
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