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

Fall Damage Script Help! Please Anyone?[EDITED!]

Asked by 10 years ago

This question has been solved by the original poster.

Now this is different from the last one I made. This is my script:

01unit = 0.5 --Seconds
02damageperunit = 1
03damage = 0
04 
05game.Players.PlayerAdded:connect(function(plyr)
06    plyr.CharacterAdded:connect(function(char)
07        local h = char:FindFirstChild("Humanoid")
08        local hrp = char:FindFirstChild("HumanoidRootPart")
09        while wait(unit) do
10            if hrp.Velocity.Y < -1 then
11                damage = damage+damageperunit
12            else
13                h:TakeDamage(damage)
14                damage = 0
15            end
16            print(damage, hrp.Velocity.Y) --Print how much damage you will take and how fast you're moving.
17        end
18    end)
19end)

As you know this script is a little glitched. If you can please fix this! Well I made a second version of this:

01unit = 1
02damageperunitmult = 1.5 --Change this to how much damage
03damage = 0
04 
05game.Players.PlayerAdded:connect(function(plyr)
06    plyr.CharacterAdded:connect(function(char)
07        local h = char:FindFirstChild("Humanoid")
08        local hrp = char:FindFirstChild("HumanoidRootPart")
09        if h then
10            h.FreeFalling:connect(function()
11                while wait(unit) do
12                    local speed = hrp.Velocity.Y
13                    if speed < 0 then
14                        damage = (speed*-1)+damageperunitmult
15                    elseif speed > 0 then
View all 23 lines...

Now they take 40 damage for just jumping! But some times when they fall from a tremendous height they take no damage. What is happening is that when they jump it takes less than a second so the "speed" variable doesn't have time to change. So the speed variable stays the same until one second passes.


I edited the script a little and I got this. Now they take 20 damage for walking and 40 for going up stairs. They get a lot more damage when they jump. Any help would be appreciated!

I asked this question before here. There was not much help but I edited the script and the edited script needs help!


I made a 3rd one! This one works better but I can't find the math for it. I'm trying to find the perfect amount of fall damage by Dividing. I divide it by 15 but It doesn't seem to do enough damage in some parts but seem to do too much damage at other parts.

01unit = 0.5 --Seconds
02damageperunit = 1
03damage = 0
04 
05game.Players.PlayerAdded:connect(function(plyr)
06    plyr.CharacterAdded:connect(function(char)
07        local h = char:FindFirstChild("Humanoid")
08        local hrp = char:FindFirstChild("HumanoidRootPart")
09        while wait(unit) do
10            if math.floor(hrp.Velocity.y * 10^5) < 0 then
11                damage = damage+((hrp.Velocity.Y*-1)/20)
12            else
13                h:TakeDamage(damage)
14                damage = 0
15            end
16            print(damage.." Damage and falling at "..math.floor(hrp.Velocity.Y*-10^5)) --Print how much damage you will take and how fast you're moving.
17        end
18    end)
19end)
0
Instead of having a loop to check and see if the character is moving faster than a certain speed, you could use the FreeFalling event of a humanoid, count the number of seconds until the humanoid stops falling, and then base your damage on that time. http://wiki.roblox.com/index.php?title=API:Class/Humanoid/FreeFalling LightArceus 110 — 10y
0
@LightArceus , I already use that, at the time that I was making this script I didn't use it. EzraNehemiah_TF2 3552 — 10y
0
Are you using Velocity as a challenge or for some specific purpose? LightArceus 110 — 10y
0
@LightArceus , I guess a challenge, but I can use the Velocity so I can give damage depending on how fast they were. EzraNehemiah_TF2 3552 — 10y

2 answers

Log in to vote
0
Answered by 10 years ago

The following is pseudo code(less pseudo code more "I deleted the exact answer") for a script that I made that works. IF you need more help I will offer some real code, but the point of this site isn't to give you all the answers.

01damageperunitmult -- damage per amount of time/velocity of the fall
02timethreshold -- the amount of time the player must fall before damage is dealt
03speedthreshold-- the speed in the Y axis the player must be falling at to receive damage
04 
05falling = false -- whether or not the player is falling
06local speed = 0  -- variable for velocity in the Y axis
07local time1 = 0  -- amount of time falling
08 
09humanoid freefalls
10    falling set to true
11    while falling do
12        add an increment to time
13        get the current speed of the humanoid
14        wait(0.04--[[ You could bind this to RenderStepped, but I didn't think that was necessary.
15        That might work better though, so you should try it.--]]
View all 27 lines...

Sorry about the wonky indentation. I'm not super literate in whatever text formatting this uses. Anyway, if it doesn't make sense feel free to ask questions, and if you really need it I can post some real code.

Edit: Figured out the indentation problem. If you don't add a new line(enter/shift+enter) a line that runs over the ends and starts a new line by itself will not respond to a space or a tab at the beginning of the automatically created line. Although what shows up on the post isn't what I see in the text editor, so I guess I'm just going to have a really hard to read post.

0
This is an old question. I don't need the script. EzraNehemiah_TF2 3552 — 10y
Ad
Log in to vote
-1
Answered by 5 years ago

There are already many scripts out there that can do this, (however walking too fast/flying is a problem)

[code]bin = script.Parent 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”) t = bin:FindFirstChild(“Torso”) ll.CanCollide = true la.CanCollide = true ra.CanCollide = true rl.CanCollide = true h.CanCollide = true t.CanCollide = true ll.Elasticity = 0 la.Elasticity = 0 ra.Elasticity = 0 rl.Elasticity = 0 h.Elasticity = 0 t.Elasticity = 0

function HitGround(part) local blah = bin:findFirstChild(“AlreadyHit”) if t.Velocity.y<-60 and part.Name~=“Pillow” and blah==nil then wee = Instance.new(“IntValue”) wee.Name = “AlreadyHit” wee.Parent = bin humanoid.Health = humanoid.Health + t.Velocity.y/3 wait(1) wee:Remove() end end

ll.Touched:connect(HitGround) rl.Touched:connect(HitGround) la.Touched:connect(HitGround) ra.Touched:connect(HitGround) h.Touched:connect(HitGround)[/code]

When I have done fall damage scripts I have usually used a circular buffer where I save the velocities of the last N frames.

This is reliable because with .Touched events, the event might come too late (and the velocity isnt the same as it was during impact) and additionally if you only check the velocity, the character will get hurt even if you just slightly touch a part when falling even if it doesnt even slow you down at all.

The buffer allows me to find the change in velocity within a short time period, so it basically causes damage whenever there is high acceleration such as when hitting the floor after a fall and quickly stopping.

Answer this question