I’m trying to make a fall damage script utilizing velocity on server, but I’m facing multiple problems though the code works.
Player gets damaged while mid-air, whilst I only want them to be hit when they’re actually landed.
Very low damage when jumping from tall height.
local Character = script.Parent
local Humanoid:Humanoid? = Character.Humanoid
while true do
task.wait(0.04)
local V1 = Character.PrimaryPart.Velocity.Y
local ABS = math.abs
local FLOOR = math.floor
local V2 = ABS(V1 * -1)
local DAMAGE = FLOOR(V2)
local DISTANCE = ABS(V2 ^ 3) / 100000
if V2 >= 100 then
print("Ragdoll") -- Ragdoll since player jumped off a very tall height
elseif V2 >= 25 and Humanoid:GetState() ~= Enum.HumanoidStateType.Jumping then
Humanoid:TakeDamage(DISTANCE)
print(DAMAGE)
end
end
first off, while loops can lag the game when there’s a lot of players in one server, i’d suggest you use runservice, also to detect if the player hit the ground you can detect if his statetype is running and do some quick maths with raycasting to calculate the damage he’s gonna take
I tried using racyast but it returns nil, and it still damages me mid way despite using HumanoidState
local Character:Model? = script.Parent
local Humanoid:Humanoid? = Character.Humanoid
local Run = game:GetService("RunService")
local Paramaters = RaycastParams.new()
Paramaters.FilterDescendantsInstances = {Character}
Paramaters.FilterType = Enum.RaycastFilterType.Exclude
function REMOVENEGATIVES(Number:number?)
return Number * -1
end
Run.Heartbeat:Connect(function()
local Raycast = workspace:Raycast(Character.PrimaryPart.Position, -Character.PrimaryPart.CFrame.UpVector * math.huge, Paramaters)
local V1 = Character.PrimaryPart.Velocity.Y
local ABS = math.abs
local FLOOR = math.floor
local V2 = ABS(V1 * -1)
local DAMAGE = FLOOR(V2)
local DISTANCE = ABS(V2 ^ 3) / 100000
if V2 >= 100 and Humanoid.StateChanged:Wait() and Raycast.Instance then
print("Ragdoll") -- Ragdoll since player jumped off a very tall height
Humanoid:TakeDamage(Humanoid.MaxHealth)
elseif V2 >= 25 and Humanoid:GetState() == Enum.HumanoidStateType.Running then
if FLOOR(DISTANCE) > 0 then
print(DISTANCE, "nat")
Humanoid:TakeDamage(DISTANCE)
end
--print(DAMAGE)
end
end)
local Character:Model? = script.Parent
local Humanoid:Humanoid? = Character.Humanoid
local Run = game:GetService("RunService")
local Paramaters = RaycastParams.new()
Paramaters.FilterDescendantsInstances = {Character}
Paramaters.FilterType = Enum.RaycastFilterType.Exclude
local distance = 0
Run.RenderStepped:Connect(function()
local Raycast = workspace:Raycast(Character.PrimaryPart.Position, -Character.HumanoidRootPart.CFrame.UpVector * 1250, Paramaters)
if Raycast.Instance then
if humanoid:GetState() == Enum.HumanoidStateType.Freefall then
local distancefromground = Character.HumanoidRootPart.Position.Y - Raycast.Instance.Position.Y
if distancefromground > distance then
distance = distancefromground
end
Humanoid.StateChanged:Connect(function()
if humanoid:GetState() == Enum.HumanoidStateType.Landed then
if distance = 0 then
humanoid:TakeDamage(distancefromground * .55)
else
humanoid:TakeDamage(distance * .55)
end
end
end)
end
end
end)
i dont know if this will work i kinda rushed it with the code
I die instantly whenever I land regardless of height but I figured, I could utlize the distance from ground to see how much has player fallen, is that ideal or not? then use local DISTANCE = ABS(V2 ^ 3) / 100000 to deal damage.