how would I go about coding fall damage?
when you fall for a certain amount of time, I want the player to take damage.
how would I go about coding fall damage?
when you fall for a certain amount of time, I want the player to take damage.
Could probably start by checking either the humanoid state or raycasting downwards (2 different methods). And then if the humanoid type is air or the raycast downwards isn’t hitting anything, you start a timer and that can be multiplied by some variable for the amount of damage it does x the amount of time the player is falling
Hi, I have come up with a solution using Character.Humanoid.FloorMaterial, which I think is what you’re looking for. This measures the time between when a player leaves solid ground and returns to it after falling. I am aware this is not practical as it could interfere with other aspects of the game (e.g. if you have a fly feature, then the script will start killing players for flying around too long), but I am only trying to give you an idea of what to centre your coding around.
My script (This is a local script that should be placed in game.StarterPack.StarterCharacterScripts):
local character = script.Parent
local hum = character:WaitForChild("Humanoid")
local startTime = 0
local endTime = 0
local damageTaken = 5 --Set this to the damage that the player will take per second spent falling
local maxTimeWithoutDamage = 3 --Set this to the maximum time, in seconds, that the player can fall without sustaining damage
hum:GetPropertyChangedSignal("FloorMaterial"):Connect(function()
if hum.FloorMaterial == Enum.Material.Air then
startTime = os.time()
elseif startTime ~= 0 then
endTime = os.time()
local timeSpentFalling = endTime - startTime
if timeSpentFalling > maxTimeWithoutDamage then
print(hum.Health)
hum.Health -= math.round(timeSpentFalling - maxTimeWithoutDamage) * 5
print(hum.Health)
end
startTime = 0
endTime = 0
end
end)
Hope this helped!
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.