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

My fall damage script keeps giving me several different errors?

Asked by 3 years ago

I'm attempting to make a fall damage script for my game, however when I try to calculate the amount of time the player has been falling it prints 'nil'

I tried to use a while loop and a repeat loop but both printed the same error: Workspace.Louscascicly.FallDamageScript:30: attempt to perform arithmetic (mul) on nil and number

Here is my script:

local PlayerService = game:GetService("Players")
local Player = PlayerService.LocalPlayer
local Character = Player.Character
local Humanoid = Character:WaitForChild("Humanoid")

local FreefallTime

local DAMAGE_PER_SECOND = 5
local FATAL_SECONDS = 15
local MINIMUM_SECONDS = 3

Humanoid.StateChanged:Connect(function(state)
    if state == Enum.HumanoidStateType.Freefall then
        repeat
            FreefallTime = FreefallTime + 1
            print(FreefallTime)
        until
            state == Enum.HumanoidStateType.Landed

    elseif state == Enum.HumanoidStateType.Landed then
        print("Landed")
        print(FreefallTime)
        if FreefallTime > MINIMUM_SECONDS then
            if FreefallTime > FATAL_SECONDS then
                Humanoid:TakeDamage(1000000000000)
            else
                local RefinedDamage = FreefallTime * DPS
                Humanoid:TakeDamage(RefinedDamage)
            end
        end
    end
end)

1 answer

Log in to vote
0
Answered by 3 years ago

You are attempting to perform math on nil, which is not possible. You will need to assign the variable to an int.

Ad

Answer this question