Pretty badly done, but it works the last time I checked.
--[[ Script Creator: Sinibus
Script Name: FreeFall v 1.0
Date Created: Nov. 25, 2012
Date Modified: Mar. 25, 2013
Script Purpose: To implement fall damage.
A player will lose 1 hit point for every 4 studs fallen, excluding safety net of 20 studs.
Notes:
1. You could make the main part of this script a function in your leaderboard or anywhere that sets up PlayerAdded. I'm doing it this way to prevent anything from being forced to be changed (designed as an independent script that can be instantly applied in any game).
2. I'm warning everyone now this could be fairly more efficient.
3. This script deals damage after any bouncing due to the nature of the FreeFalling event. If you want to stop bouncing, set the Elasticity of the character's parts to 0.
4. Characters are five studs tall. The odds this script will change a character from full health to none is rather low.
5. Characters will not be harmed if they have a ForceField.
]]
-- STAGE ONE: Variable Initialization
-- should these be local?
minHeightToDamage = 20
HeightToKill = 400 -- 1 damage * 4 studs * 100 health
-- STAGE TWO: Function Initialization
-- all functions used are anonymous
-- I could modularize it more, but it is short enough to not need it
-- STAGE THREE: Input
-- no user input
-- STAGE FOUR: Processing
-- hook up player added and character added
game.Players.PlayerAdded:connect(function(player)
player.CharacterAdded:connect(function(character)
-- set up variables needed inside of the FreeFalling section.
local debounce = true
local fall = false -- do we need this variable at all?
character.Humanoid.FreeFalling:connect(function(falling) -- this event is odd
-- Listeners have been set up, figure out if falling
fall = falling -- this event is always connected and updating
if fall and debounce then
debounce = false -- employ basic debounce system
local position = -math.huge -- not set to 0 to avoid falls under the baseplate
local endposition = math.huge -- these values will change
-- first positions designed so change will always occur.
while fall do
print("falling")
if position < character.Torso.Position.Y then
position = character.Torso.Position.Y
end
-- new if statement. not an elseif because both values change during first loop
if endposition > character.Torso.Position.Y then
endposition = character.Torso.Position.Y
end
wait()
end
print("loop ended")
local deltaY = position - endposition
print(deltaY)
local shouldDamage = deltaY - minHeightToDamage
if shouldDamage > 0 then -- height fallen must exceed the min. height
damage = math.floor(deltaY/4)
print(damage)
character.Humanoid:TakeDamage(damage)
print("damage applied")
end
debounce = true
end
end)
end)
end)
-- STAGE FIVE: Output
-- output/changes handled inside of nested functions (health is changed).