Hey, i was wondering if there’s way to make it so npc’s only respawn after you move a certain distance away?
Yes there is. What does your current respawning code look 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.
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.
Off topic and spam