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

How do I get my fall damage script to work?

Asked by 10 years ago

I've been working on this script for a while now, it's Clonetropper1019's falling damage script, but I can't figure out how to get it to work. It's pretty cool, with the damage sound, and such. But I'd also like to make it so that if you take more than 25% of your health from falling, it'll play a sound. And if 30% or more is taken, it plays another sound. I have Half Life 2 sounds on my laptop, and I'd like to use them, but currently, I can't exactly figure out to get this script to work, nor can I figure out how to add onto script. Can someone please help me? If someone can, thanks.

local minimumFallTime = 0.75
-- ^ The minimum time the player has to fall to take damage
local damagePercent = 0.5
-- ^ If its 0.5, their damage is 50% of their MaxHealth * the time they fell
----------------------------------------------------------------------------
local Humanoid = script.Parent.Humanoid
local falling = false

function notFreeFalling()
        falling = false
end

function FreeFalling()
        falling = true
end

Humanoid.Died:connect(notFreeFalling)
Humanoid.Running:connect(notFreeFalling)
Humanoid.Jumping:connect(notFreeFalling)
Humanoid.Climbing:connect(notFreeFalling)
Humanoid.GettingUp:connect(notFreeFalling)
Humanoid.FallingDown:connect(notFreeFalling)
Humanoid.Seated:connect(notFreeFalling)
Humanoid.PlatformStanding:connect(notFreeFalling)

Humanoid.FreeFalling:connect(FreeFalling)


local hurtSound
while not hurtSound do
        for _,v in pairs(script.Parent:WaitForChild("Head"):GetChildren()) do
                if v:IsA("Sound") and  v.SoundId == "rbxasset://sounds/uuhhh.wav" then
                        hurtSound = v
                        break
                end
        end
        wait()
end

while wait() do
        if falling then
                local start = tick()
                repeat wait() until not falling
                print(tick()-start)
                if tick()-start >= minimumFallTime then
                        local h,m = Humanoid.Health,Humanoid.MaxHealth
                        local damage = (tick()-start)*(m*damagePercent)
                        hurtSound:Play()
                        Humanoid:TakeDamage((h<damage) and h or damage)
                end
        end
end

0
Can someone tell me how to get this script to work? Please? TheRings0fSaturn 28 — 10y

1 answer

Log in to vote
-2
Answered by 10 years ago

This might work... Remember to change sound1 and sound2 into asset links... Also, Sound2 is the <70% one

local minimumFallTime = 0.75
-- ^ The minimum time the player has to fall to take damage
local damagePercent = 0.5
-- ^ If its 0.5, their damage is 50% of their MaxHealth * the time they fell
local sound1 = "Sound Asset ID"
local sound2 = "Sound Asset ID"
----------------------------------------------------------------------------
local Humanoid = script.Parent.Humanoid
local falling = false

function notFreeFalling()
        falling = false
end

function FreeFalling()
        falling = true
end

Humanoid.Died:connect(notFreeFalling)
Humanoid.Running:connect(notFreeFalling)
Humanoid.Jumping:connect(notFreeFalling)
Humanoid.Climbing:connect(notFreeFalling)
Humanoid.GettingUp:connect(notFreeFalling)
Humanoid.FallingDown:connect(notFreeFalling)
Humanoid.Seated:connect(notFreeFalling)
Humanoid.PlatformStanding:connect(notFreeFalling)

Humanoid.FreeFalling:connect(FreeFalling)


local hurtSound
while not hurtSound do
        for _,v in pairs(script.Parent:WaitForChild("Head"):GetChildren()) do
                if v:IsA("Sound") and  v.SoundId == "rbxasset://sounds/uuhhh.wav" then
                        hurtSound = v
                        break
                end
        end
        wait()
end

while wait() do
        if falling then
                local start = tick()
                repeat wait() until not falling
                print(tick()-start)
                if tick()-start >= minimumFallTime then
                        local h,m = Humanoid.Health,Humanoid.MaxHealth
                        local damage = (tick()-start)*(m*damagePercent)
                       if m*0.7 > damage then
            sound1:Play()
            elseif m*0.75 > damage then
            sound2:Play()
            end
                        Humanoid:TakeDamage((h<damage) and h or damage)
                end
        end
end

0
Can you vote me back up? xd 31337n00b 0 — 10y
0
Alright, thank you. I'll see if it works. :) TheRings0fSaturn 28 — 10y
Ad

Answer this question