How to relife character at nearest spawnLocation from dead position?

In the case of many spawnlocation.
I want respawn at the nearest one ,without random .
How to make it?

Inside of a Humanoid.Died function, it would look something like this.

local function distanceBetween(p1, p2)
    return (p1.Position - p2.Position).Magnitude

local distances = {}
for _,spawn in pairs(spawnsFolder:GetChildren()) do
    distance[spawn] = distanceBetween(head, spawn)

local closestSpawn = nil
local currentClosestDistance = 1e6
for spawn,distance in pairs(distances) do
    if distance <= currentClosestDistance then
        closestSpawn = spawn
        currentClosestDistance = distance

if closestSpawn and closestSpawn:IsA("SpawnLocation") then
     player.SpawnLocation = closestSpawn

Then in a .CharacterAdded event you’d reset their SpawnLocation property. This logic should work, although untested and if you just paste this code into a script it won’t work. This is more just the pseudo-code.

1 Like

Thank you very much for helping me.
Player.RespawnLocation is the key point.
And I found this setting is valid on server side only.