I wanted to try making a basic fall damage script for future purposes, but for some reason, fall damage isn't being taken. What can I do?
01 | local y = nil |
02 | _G.Changed(game.Players.LocalPlayer.Character.Humanoid, "FloorMaterial" , function (material,past,hum) -- Used a slightly different custom changed function, works like GetPropertyChangedSignal except it provides the current and previous value (the 3rd argument is just the part itself) |
03 | if material = = Enum.Material.Air and not y then |
04 | y = hum.RootPart.Y |
05 | end |
06 | if y and material ~ = Enum.Material.Air then |
07 | local newy = hum.RootPart.Y |
08 | local diff = math.abs(newy-y) - 10 |
09 | if diff < 10 then diff = 0 end |
10 | hum:TakeDamage(diff) |
11 | print ( "Damage taken: " .. tostring (diff)) |
12 | y = nil |
13 | end |
14 | end ) |
the function in question, juuust in case it's needed
01 | _G.Changed = function (part, PropertyName, func) |
02 | local current = part [ PropertyName ] |
03 | coroutine.resume(coroutine.create( function () |
04 | while true do |
05 | repeat game.RunService.RenderStepped:wait() until part [ PropertyName ] ~ = current |
06 | coroutine.resume(coroutine.create( function () |
07 | func(part [ PropertyName ] , current, part) |
08 | end )) |
09 | current = part [ PropertyName ] |
10 | end |
11 | end )) |
12 | end |