Npc respawn after you move away

Hey, i was wondering if there’s way to make it so npc’s only respawn after you move a certain distance away?

1 Like

Yes there is. What does your current respawning code look like?

1 Like

You can use the magnitude of the NPC to the player:


local RespawnDistance = 40 -- in studs


local function RespawnOnDistance(NpcPosition, PlayerPos)
   local Distance = (NpcPosition - PlayerPos). magnitude -- distance in studs
   
   if (Distance > RespawnDistance) then
      return true
   end
   return false
end

The function above takes in the position of the NPC and player. It then calculates the magnitude (Distance) between them.
If the Distance is greater than the RespawnDistance then the function returns true which can be used to trigger a respawn. If the other case it returns false, meaning the Player is within the RespawnDistance.

1 Like

Off topic and spam :skull::face_exhaling:
( char-limit)

1 Like