Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do you create fall damage?

The title says it all. I have tried learning how to do this from free models but none of them work. I don't even know where to start

1 comment

0

I think I would do it via raycasting a ray from a player's torso downwards. You could get a distance and then check if the player's jumping or performing a normal activity. If they're not though and the distance is > the jump distance then you could create an equation to determine how much damage to make them take.

3 answers

local Fall_Damage_Begin = 10
local Fall_Damage_Scale = 1

local Player = game.Players.LocalPlayer
local Last_Y = Player.Character.Torso.Position.Y

function onFreeFall(active)
    if (active) then
        Last_Y = Player.Character.Torso.Position.Y
    else
        local y_diff = Last_Y - Player.Character.Torso.Position.Y --the difference between the fall start position and the fall end position
        if (y_diff > Fall_Damage_Begin) then
            local damage = (y_diff - Fall_Damage_Begin) * Fall_Damage_Scale --damage is based on the extra fall distance after Fall_Damage_Begin, and multiplied by Fall_Damage_Scale
            Player.Character.Humanoid:TakeDamage(damage) --using the TakeDamage() method means that with a forcefield, the player won't take damage
        end
    end
end

Player.Character.Humanoid.FreeFalling:connect(onFreeFall)

This may work. I havent tested it, but it should. Let me know if it does.

4 comments

0

This didn't work.

0

Are you using R15?

0

Sorry for "Necroposting" but i think you can change torso to humanoidrootpart.

0

Change Torso to UpperTorso or LowerTorso accordingly. this should work with new rigs.

Thank you so much TickTockTheory!

I was able to use your code and tweak it a bit. I tested it in studio and worked great! This is for a R15 rig

local Fall_Damage_Begin = 10
local Fall_Damage_Scale = 1

local me = script.Parent.Name
local Player = game.workspace:FindFirstChild(me)
local myTorso = Player:WaitForChild("UpperTorso")
local Last_Y = myTorso.Position.Y

function onFreeFall(active)
	if (active) then
		Last_Y = Player.UpperTorso.Position.Y
	else
		local y_diff = Last_Y - Player.UpperTorso.Position.Y
		if(y_diff > Fall_Damage_Begin) then
			local damage = (y_diff - Fall_Damage_Begin) * Fall_Damage_Scale
			Player.Humanoid:TakeDamage(damage)
		end
	end
end

Player.Humanoid.FreeFalling:connect(onFreeFall)

This discussion is preserved as it was. New answers, comments, and votes are closed.