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

Why does my fall damage script kill you when the character is in a negative Y value?

Asked by 7 years ago

I know I'm bad at phrasing titles, but my point is that whenever the character is in a Y-axis of (0,-1,0) and below, it just automatically dies. I do not know at all why! Also, in some general cases, the character just dies for unkown reasons because of fall damage. If you can help me improve this script or create an entirely new one, it would be a great help. (This was taken from free models and edited from me so I could learn)

wait(5)

bin = script.Parent
probability = math.random(-2, 10)
humanoid = bin:FindFirstChild("Humanoid")
ll = bin:FindFirstChild("Left Leg")
rl = bin:FindFirstChild("Right Leg")
la = bin:FindFirstChild("Left Arm")
ra = bin:FindFirstChild("Right Arm")
h = bin:FindFirstChild("Head")
freefall = false
startingHeight = 0
endingHeight = 0
ll.Elasticity = 0
rl.Elasticity = 0
la.Elasticity = 0
ra.Elasticity = 0
h.Elasticity = 0
bin.Torso.Elasticity = 0

function onFreeFall()
    freefall = true
    wait(.25)
    startingHeight = bin.Torso.Position.y
end

function onTouched(part) --The ground has been touched.
    if freefall == true and bin:findFirstChild("Parachute") == nil and humanoid.Health > 0 and part.CanCollide == true then 

        endingHeight = bin.Torso.Position.y
        local averageHeight =  startingHeight - endingHeight
        if averageHeight > 25 then
            if bin:FindFirstChild("Torso") and bin.Torso:FindFirstChild("Crunch") then
                bin.Torso.Crunch:Play()
            end
            humanoid.Health = humanoid.Health - ((averageHeight * 0.1)^2)
            startingHeight = 0
        end
    end
end


humanoid.FreeFalling:connect(onFreeFall)
ll.Touched:connect(onTouched)
rl.Touched:connect(onTouched)
la.Touched:connect(onTouched)
ra.Touched:connect(onTouched)
h.Touched:connect(onTouched)

1 answer

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

Try using this in a script in ServerStorage. If that does not work, tell me the errors.

Don't forget to accept this answer if it helped!

EDIT: I made a mistake. I put :GetAllChildren() instead of :GetChildren()

R6:

wait(1)
local MaxVelocity = 15
local DMGperVelocity = 3
game.Players.PlayerAdded:connect(function(plr)
    local FreeFall = false
    plr.Character.Humanoid.FreeFalling:connect(function()
        FreeFall = true
    end)
    plr.Character:GetChildren().Touched:connect(function()
        if plr.Character.Velocity >= MaxVelocity then
            plr.Character.Humanoid.Health =  plr.Character.Humanoid.Health - (plr.Character.Torso.Velocity * DMGperVelocity) 
        end
    end)
end)

R15:

wait(1)
local MaxVelocity = 15
local DMGperVelocity = 3
game.Players.PlayerAdded:connect(function(plr)
    local FreeFall = false
    plr.Character.Humanoid.FreeFalling:connect(function()
        FreeFall = true
    end)
    plr.Character:GetChildren().Touched:connect(function()
        if plr.Character.Velocity >= MaxVelocity then
            plr.Character.Humanoid.Health =  plr.Character.Humanoid.Health - (plr.Character.UpperTorso.Velocity * DMGperVelocity) 
        end
    end)
end)
0
man. I already know this doesnt work. You use GetAllChildren(). laughablehaha 494 — 7y
Ad

Answer this question