generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: FreeFalling Event?

Previous Thread :: Next Thread 
Solotaire is not online. Solotaire
Joined: 30 Jul 2009
Total Posts: 30356
25 Nov 2012 03:28 PM
I'm currently trying to create a basic fall damage script using the FreeFalling event, but it always seems to be set to true, even when I'm standing still on the spawnlocation. What should I do to fix this?
Report Abuse
Solotaire is not online. Solotaire
Joined: 30 Jul 2009
Total Posts: 30356
25 Nov 2012 04:13 PM
Here's some of the code:
game.Players.PlayerAdded:connect(function(player)
print('player added')
player.CharacterAdded:connect(function(character)
character.Humanoid.FreeFalling:connect(function() -- this event is odd

repeat print('free fall')wait() until character.Humanoid.FreeFalling == false
end)
end)
end)

It starts to print 'free fall' as soon as I enter the server and doesn't stop. I'm standing normally on the spawn location.
Report Abuse
thedeathmaster01 is not online. thedeathmaster01
Joined: 14 Mar 2010
Total Posts: 6331
25 Nov 2012 04:15 PM
game.Players.PlayerAdded:connect(function(player)
player.CharacterAdded:connect(function(character)
repeat wait() until character.Humanoid
character.Humanoid.FreeFalling:connect(function() -- this event is odd
while character.Humanoid.FreeFall do
print("free fall")
wait()
end
end)
end)
end)
Report Abuse
Solotaire is not online. Solotaire
Joined: 30 Jul 2009
Total Posts: 30356
25 Nov 2012 04:18 PM
"FreeFall is not a valid member of Humanoid"?
Report Abuse
xXTheRobotXx is not online. xXTheRobotXx
Joined: 05 May 2012
Total Posts: 13343
25 Nov 2012 04:19 PM
game.Players.PlayerAdded:connect(function(player)
player.CharacterAdded:connect(function(character)
repeat wait() until character.Humanoid
character.Humanoid.FreeFalling:connect(function() -- this event is odd
while character.Humanoid.FreeFalling do
print("free fall")
wait()
end
end)
end)
end)

Fixed death's?

Error 407:["Siggy.exe not found."] Please try again in a few moments.
Report Abuse
Solotaire is not online. Solotaire
Joined: 30 Jul 2009
Total Posts: 30356
25 Nov 2012 04:23 PM
No, that is going to give the same infinite loop error while I stand on the spawn. The only change between the two is that death is using a while loop over a repeat.
Report Abuse
doombringer42 is not online. doombringer42
Joined: 13 Nov 2007
Total Posts: 5445
25 Nov 2012 04:24 PM
FreeFalling is an event... i didn't think events could be used in that way?

¬ SHG Scripter Tier-2 ♣ LuaLearners Elite
Report Abuse
UndefinedScripter is not online. UndefinedScripter
Joined: 07 Oct 2012
Total Posts: 115
25 Nov 2012 04:24 PM
I would use the Changed event on the torso myself, of course you have to work more with numbers this way, but it is allot less-likely to glitch on you.
Report Abuse
Solotaire is not online. Solotaire
Joined: 30 Jul 2009
Total Posts: 30356
25 Nov 2012 04:30 PM
@UndefinedScripter,

Not sure how I would do that. I think I'd be measuring velocity that way, but I'm not sure how to set up when it ends and starts.

What I'm currently doing (with the freefalling event) is:
position = character.Torso.Position.Y
repeat print('free fall')wait() until character.Humanoid.FreeFalling == false
newposition = character.Torso.Position.Y

deltaY = position - newposition -- change in position
if deltaY >= 20 then -- players lose health starting from 1 meter+ falls
damage = math.floor(deltaY / 4) -- lose one health for every four additional studs fallen.
character.Humanoid.Health = character.Humanoid.Health - damage
end

It gets the start and end positions and deals damage based on height.
Report Abuse
UndefinedScripter is not online. UndefinedScripter
Joined: 07 Oct 2012
Total Posts: 115
25 Nov 2012 04:37 PM
This actually has inspired me to make a tool to were if your falling I would use :GetMouse, and if you do not press the key at the right time you will not land correctly and you will take damage, but if you land correctly no damage would be taken, it would be great for a ninja game. ​>.> But back to your respective code.


I do not use repeat that often, mostly because it is really glitch, try this instead.

while wait() do
if Character.Humanoid.FreeFalling == true then
wait()
elseif Character.Humanoid.FreeFalling == false then
break
end
end

This may not be the problem, it was just the first thing I cam accrossed that could be the problem, if it keeps glitching, I will read more into it.
Report Abuse
nate890 is not online. nate890
Joined: 22 Nov 2008
Total Posts: 21686
25 Nov 2012 04:40 PM
fluke: http://www.roblox.com/Damage-on-Fall-item?id=98822611
Report Abuse
Solotaire is not online. Solotaire
Joined: 30 Jul 2009
Total Posts: 30356
25 Nov 2012 04:45 PM
game.Players.PlayerAdded:connect(function(player)
print('player added')
player.CharacterAdded:connect(function(character)
while wait() do
if character.Humanoid.FreeFalling == true then
wait()
print'waiting'
elseif character.Humanoid.FreeFalling == false then
print'breaking'
break
end
end
end)
end)


Output:
> player added
It doesn't print either. I think it is because FreeFalling is actually an event? I'm looking at the wiki page, but not sure what I would do to fix this.
Report Abuse
nate890 is not online. nate890
Joined: 22 Nov 2008
Total Posts: 21686
25 Nov 2012 04:46 PM
It's because FreeFalling isn't a property of humanoid. You need to use the first parameter of the FreeFalling event, like I did in the model I posted.

Here's the code:

local lowestFallHeight = 8 --how many studs you must fall before damage is inflicted
local maxFallHeight = 25 --if fallen from this many studs, 100% of health will be inflicted

local humanoid = script.Parent
local torso = humanoid.Parent.Torso

local isFalling = false
local deb = false

humanoid.FreeFalling:connect(function(falling)
isFalling = falling
if isFalling and not deb then
deb = true
local maxHeight, lowHeight = 0, math.huge
while isFalling do
local height = torso.Position.y
if height > maxHeight then
maxHeight = height
end
if height < lowHeight then
lowHeight = height
end
wait()
end
local fallHeight = maxHeight - lowHeight
local impactHeight = fallHeight - lowestFallHeight
if impactHeight > 0 then
local damage = impactHeight * (humanoid.MaxHealth / maxFallHeight)
humanoid:TakeDamage(damage)
end
deb = false
end
end)
Report Abuse
Solotaire is not online. Solotaire
Joined: 30 Jul 2009
Total Posts: 30356
25 Nov 2012 04:48 PM
Oh, I think get it now. I'm going to edit that code and see what happens. Thank you.
Report Abuse
nate890 is not online. nate890
Joined: 22 Nov 2008
Total Posts: 21686
25 Nov 2012 04:49 PM
yup
Report Abuse
UndefinedScripter is not online. UndefinedScripter
Joined: 07 Oct 2012
Total Posts: 115
25 Nov 2012 05:06 PM
Oh, yeah sorry. Atleast nate figured out the problem though.
Report Abuse
ForeverDev is not online. ForeverDev
Joined: 04 Oct 2008
Total Posts: 13300
30 Sep 2014 09:54 PM
noobs

local player = game.Players.LocalPlayer
repeat wait() until player.Character
local humanoid = player.Character:WaitForChild("Humanoid")

local startPosition;

humanoid.FreeFalling:connect(function(active)
if active then
startPosition = player.Character.Torso.Position
elseif startPosition then
local fell = startPosition.Y - player.Character.Torso.Position.Y
if fell > 15 then
humanoid:TakeDamage(fell / 2)
end
end
end)



-ForeverDev
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image