Fall Damage
Hi !
I will explain how to calculate the fall damage thanks to the height of the fall :
- Get Y of the player with
Character:GetPrimaryPartCFrame().Position.Y
! - When the player fall define his height !
- When the player land define his height !
- Check if the player land in the water, if the player land in water and the height is <100 kill the player else apply the damage by subtracting the height of when you fall from that of when you land .
Schema :
Finish !
I now show you the script placed in ServerScriptService :
game.Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(Character)
local Humanoid = Character:FindFirstChildOfClass("Humanoid")
local YF
local YL
Humanoid.StateChanged:Connect(function(OldState, NewState)
if NewState == Enum.HumanoidStateType.Freefall then
YF = Character:GetPrimaryPartCFrame().Position.Y
elseif OldState == Enum.HumanoidStateType.Freefall and NewState ~= Enum.HumanoidStateType.Swimming then
YL = Character:GetPrimaryPartCFrame().Position.Y
if YF > YL and YF - YL < -20 then
Humanoid:TakeDamage(YF - YL*-1)
elseif YF - YL > 20 then
Humanoid:TakeDamage(YF - YL)
end
elseif OldState == Enum.HumanoidStateType.Freefall and NewState == Enum.HumanoidStateType.Swimming then
YL = Character:GetPrimaryPartCFrame().Position.Y
if YF > YL and YF - YL < -100 or YF - YL > 100 then
Humanoid:TakeDamage(Humanoid.MaxHealth)
end
end
end)
end)
end)
Now I let you send me your positive/negative feedback :
- This topic is well explained !
- This topic is poorly explained !
0 voters
- This topic was useful to you !
- This topic wasn’t useful to you !
0 voters
Have a good day !