I am trying to make a part stare at a player, when I make it’s shape a ball it works fine, however when the part is a cube, it starts to drift onto the ground, I have considered making the square uncollideable and using an invisible ball for the hitbox, but for various reasons I need to keep it with collision on in my game, here’s the current code for it, if you know anyway to fix this, it would be greatly appreciated:
local plrs = game:GetService("Players")
local runService = game:GetService("RunService")
local looker = script.Parent.Looker
local function GetNearestPlayer()
local lowestMag, plr = math.huge, nil
for i, v in pairs(plrs:GetPlayers()) do
if v.Character == nil or v.Character.PrimaryPart == nil then continue end
local min = math.min(lowestMag, (v.Character.PrimaryPart.Position - looker.Position).Magnitude)
if min ~= lowestMag then
lowestMag = min
plr = v
end
end
return plr
end
while runService.Heartbeat:Wait() do
local nearPlr = GetNearestPlayer()
if nearPlr == nil then continue end
looker:PivotTo(CFrame.new(looker.Position, nearPlr.Character.PrimaryPart.Position))
end