I also put in a break. If the player is within 200 units stop looking. Would this be more efficient in most cases?
Reason being if a person is within 200 units anyway they have probably seen the event so cna comment on it and it stops the loop so stops checking the rest of the players.
This is hooked to player death so killer and victim and players.
It will proceed to check if playerWitness is killer if true then play taunt, else say “oh god!”
local playerWitness = killer
local distancePlayer = 30000
for k,v in pairs(player.GetAll()) do
if v:GetPos():Distance(victim:GetPos()) < distancePlayer and v:alive() and v != victim then
distancePlayer = v:GetPos():Distance(victim:GetPos())
playerWitness = v
-- 200 is close enough no point in looping thru every1
if distancePlayer < 200 then break end
Will the break generally make it less expensive
Its part of a larger function so the indentation is a lil skew wiff