I am making a turret that I want to target random individuals within a certain distance and not just the closest player. I'm having trouble starting it though as I have never really worked much with distances before and such, so I'm completely clueless on this. So basically, how would I create a table of players within a certain distance to a part?
You can use DistanceFromCharacter to get the distance from the character's head.
local turret -- define turret local radius=20 local list={} for _,v in pairs(game.Players:GetPlayers())do local dist=v:DistanceFromCharacter(turret.Position) if dist~=0 and dist<radius then list[#list+1]=v end end
DistanceFromCharacter will return 0 if the distance cannot be found for some reason (no head/no character.)