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

Fall Damage Script Help! Please?

Asked by 9 years ago

Below is my script:

unit = 0.5 --Seconds
damageperunit = 1
damage = 0

game.Players.PlayerAdded:connect(function(plyr)
    plyr.CharacterAdded:connect(function(char)
        local h = char:FindFirstChild("Humanoid")
        local hrp = char:FindFirstChild("HumanoidRootPart")
        while wait(unit) do
            if hrp.Velocity.Y < 0 then
                damage = damage+damageperunit
                else
                h:TakeDamage(damage)
                damage = 0
                end
            print(damage, hrp.Velocity.Y) --Print how much damage you will take and how fast you're moving.
        end
    end)
end)

Thanks to NotsoPenguin, he gave me an Idea with his script.


This works perfectly fine except that when the player hits the ground they take no damage until seconds later because the HumanoidRootPart is still going at 0.0000000001 or something. Another thing is I used this command line:

workspace.Player1.Torso.CFrame = CFrame.new(Vector3.new(workspace.Player1.Torso.Position.X,workspace.Player1.Torso.Position.Y+99999,workspace.Player1.Torso.Position.Z))

It should keep adding more damage points per unit or half second, It only switches between 1 to 0 damage.


Should I fix this script or should I multiply -1.5 to the Velocity?

h:TakeDamage(Velocity*-1.5)

1 answer

Log in to vote
0
Answered by 9 years ago

Just a tip: You should put the code in a local script inside of StarterGui or StarterPack so that you don't have to use events. From there you can reference the character with game.Players.LocalPlayer.Character or script.Parent.Parent.Character

This script has a lot of problems with it. First of all, if the user were to accelerate upwards slowly and pass 0, then they would still take fall damage without hitting touching anything. Additionally, the damage is based on time in air. It should be triggered after a specified time in air, and the damage should then be based on velocity. You should have the script set to where it does damage whenever the player touches a surface that is beneath it after a specified time in air based off of velocity. You should also make it to where when damage is done, it should be at a certain velocity. i.e. this way if the player jumps, he won't take damage for every jump he does, but he will if he jumps off the roof of a building. I might make my own script and post it here for you to use for reference. As for your current problem, if you still decide on using your current code, I suggest you do something like this:

if math.floor(hrp.Velocity.y * 10^5) <= 0 then --run code here end

0
Aditionally, the bug with the humanoid root part might be because of roblox's new player animations, i.e. bobbing up and down while he's standing still. aquathorn321 858 — 9y
0
Nope. The bobbing up and down affects the torso. Not the HumanoidRootPart. The new animations has nothing to do with this glitch. EzraNehemiah_TF2 3552 — 9y
Ad

Answer this question