How to make Too far from spawn = die

How do i make it so that after reaching a certain point from spawn u will die,
Is this even possible?
Thanks for reading
the spikey man

horrible way to do it, but this could work:

while true do
    for _, plr in ipairs(game.Players:GetPlayers()) do
      if (plr.Character.HumanoidRootPart.Position - game.Workspace.Spawn.Position).Magnitude > 250 then
        plr.Character.Humanoid.Health = 0
    end
   end
    wait(1)
end

it said attempt to index nil with ‘HumanoidRootPart’

you need to check if character exists first

try this

while true do
    for _, plr in ipairs(game.Players:GetPlayers()) do
        if plr.Character and (plr.Character.HumanoidRootPart.Position - game.Workspace.Spawn.Position).Magnitude > 250 then
            plr.Character.Humanoid.Health = 0
        end
    end
    wait(1)
end

Maybe try this code? It works for me fine.
I hope this will work.

local point = workspace.SpawnLocation.Position -- your position of spawn/spawnLocation, must be a Vector3 

local range = 25 -- your range

local function onCharacterAdded(character) 
	local humanoidRootPart = character:WaitForChild("HumanoidRootPart") -- waiting for humanoidRootPart to load
	local humanoid = character:WaitForChild("Humanoid") -- waiting for humanoid to load
	
	game:GetService("RunService").Heartbeat:Connect(function() -- creating heartbeat function
		local distance = (humanoidRootPart.Position - point).Magnitude -- getting distance between player and point(Position)
		if distance > range then -- checking if distance is bigger than range 
			humanoid.Health = 0 -- setting player's health on 0 
		end
	end)
end

local function onPlayerAdded(player)
	player.CharacterAdded:Connect(onCharacterAdded) -- getting character 
end
game.Players.PlayerAdded:Connect(onPlayerAdded) -- getting player

This should work fine.

local spawnpoint = workspace:FindFirstChildOfClass("SpawnLocation") -- put spawn location here
local player = game.Players.LocalPlayer
local range = 50 -- amount of studs away that is 'too far'

game:GetService("RunService").RenderStepped:Connect(function()
	if player.Character and player.Character:FindFirstChild("HumanoidRootPart") then
		if (player.Character.HumanoidRootPart.Position - spawnpoint.Position).Magnitude >= range then
			player.Character:BreakJoints() -- Kills player
			print("Local player walked too far!")
		end
	end
end)```

use Character:WaitForChild("HumanoidRootPart)