Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do you create fall damage?

Asked by 7 years ago

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

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. AstrealDev 728 — 7y

3 answers

Log in to vote
0
Answered by 7 years ago
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.

0
This didn't work. Notpace 2 — 7y
0
Are you using R15? TickTockTheory 106 — 7y
0
Sorry for "Necroposting" but i think you can change torso to humanoidrootpart. hasanchik 49 — 4y
0
Change Torso to UpperTorso or LowerTorso accordingly. this should work with new rigs. marine5575 359 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

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)
Log in to vote
-1
Answered by
JollyDumb -21
7 years ago

If ur to lazy to script there is a Fall Damage plugin https://web.roblox.com/library/199233141/Fall-Damage-Plugin

0
humanoid.FreeFalling or humanoid.FallingDown fire a whileloop that adds while they fall and when they stop they take dammage TheScriptKing 102 — 7y
0
Doesn't work for R15 rigs. Notpace 2 — 7y

Answer this question