Skinstashery
Roblox
Home / Roblox / Studio script library / Anti-fall void reset
RB-004

Roblox anti-fall void reset script

Respawns players who fall below the map so they do not fall forever.

Script type
Script
Where it goes
ServerScriptService
Category
Admin and safety

For your own game in Roblox Studio. Not for use in other people's games.

The code

-- Anti-fall: if a player drops below VOID_HEIGHT, they respawn.

local VOID_HEIGHT = -100     -- the Y height under your map. Pick a number lower than the lowest part.
local CHECK_EVERY = 0.5      -- seconds between checks

local Players = game:GetService("Players")

-- Roblox deletes anything below this height anyway (default -500).
-- Making sure our line is above it:
if VOID_HEIGHT <= workspace.FallenPartsDestroyHeight then
	warn("VOID_HEIGHT should be higher than workspace.FallenPartsDestroyHeight")
end

while true do
	for _, player in Players:GetPlayers() do
		local character = player.Character
		local humanoid = character and character:FindFirstChildOfClass("Humanoid")
		local root = character and character:FindFirstChild("HumanoidRootPart")

		if humanoid and root and humanoid.Health > 0 and root.Position.Y < VOID_HEIGHT then
			humanoid.Health = 0   -- the player respawns at their spawn or checkpoint
		end
	end
	task.wait(CHECK_EVERY)
end

How to set it up

  1. Look at the lowest part of your map. In the Properties window, note its Position Y value.
  2. Add a Script to ServerScriptService and paste the code.
  3. Set VOID_HEIGHT to a number a bit lower than that Y value, for example 50 studs lower.
  4. Play, walk off the edge, and check that you respawn.

Change it

More in Admin and safety

All Roblox scripts

More Roblox tools