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: Swimming event script not working properly

Previous Thread :: Next Thread 
Paramedic4 is not online. Paramedic4
Joined: 23 Jan 2011
Total Posts: 5934
27 Jun 2014 12:43 AM
This script is supposed to take away health if a player is in the terrain water but when the player is not in the water anymore, it still takes away health. Why won't this script work properly?

game.Players.PlayerAdded:connect(function(Player)
Player.CharacterAdded:connect(function(char)
local humanoid = char:WaitForChild("Humanoid")
local drown = false

humanoid.Swimming:connect(function(swim)
if swim then drown = true
elseif not swim then drown = false
end
end)

while wait(1) do
if drown then humanoid:TakeDamage(5)
end
end

end)
end)
Report Abuse
AnonyAnonymous is not online. AnonyAnonymous
Joined: 23 Jun 2013
Total Posts: 6332
27 Jun 2014 12:50 AM
I'm not entirely sure however try changing "if then humanoid:TakeDamage(5)" to
if drown == true
Report Abuse
Paramedic4 is not online. Paramedic4
Joined: 23 Jan 2011
Total Posts: 5934
27 Jun 2014 01:37 AM
if drown and if drown == true are basically the same. Anyone know the problem?
Report Abuse
AnonyAnonymous is not online. AnonyAnonymous
Joined: 23 Jun 2013
Total Posts: 6332
27 Jun 2014 01:45 AM
humanoid.Swimming:connect(function(swim)
while wait(1) do
if swim then drown = true
if drown then humanoid:TakeDamage(5)
elseif not swim then drown = false
???
Report Abuse
Paramedic4 is not online. Paramedic4
Joined: 23 Jan 2011
Total Posts: 5934
27 Jun 2014 05:05 AM
Still won't work, anyone know why?
Report Abuse
Paramedic4 is not online. Paramedic4
Joined: 23 Jan 2011
Total Posts: 5934
27 Jun 2014 05:20 AM
Anyone?
Report Abuse
Paramedic4 is not online. Paramedic4
Joined: 23 Jan 2011
Total Posts: 5934
28 Jun 2014 12:58 AM
Help?
Report Abuse
Paramedic4 is not online. Paramedic4
Joined: 23 Jan 2011
Total Posts: 5934
28 Jun 2014 01:01 AM
Help please?
Report Abuse
Paramedic4 is not online. Paramedic4
Joined: 23 Jan 2011
Total Posts: 5934
28 Jun 2014 01:11 AM
Help!
Report Abuse
Paramedic4 is not online. Paramedic4
Joined: 23 Jan 2011
Total Posts: 5934
28 Jun 2014 01:22 AM
Anyone?
Report Abuse
AnonyAnonymous is not online. AnonyAnonymous
Joined: 23 Jun 2013
Total Posts: 6332
28 Jun 2014 01:23 AM
Try this:
game.Players.PlayerAdded:connect(function(Player)
Player.CharacterAdded:connect(function(char)
local humanoid = char:WaitForChild("Humanoid")
local drown = false

humanoid.Swimming:connect(function(swim)
if swim > 0 then drown = true
elseif swim < 1 then drown = false
end
end)

while wait(1) do
if drown then humanoid:TakeDamage(5)
end
end

end)
end)
Report Abuse
Paramedic4 is not online. Paramedic4
Joined: 23 Jan 2011
Total Posts: 5934
28 Jun 2014 02:09 AM
It worked! :D But can I also make it take away health even if the player is in the terrain water at idle(No speed)?
Report Abuse
AnonyAnonymous is not online. AnonyAnonymous
Joined: 23 Jun 2013
Total Posts: 6332
28 Jun 2014 02:14 AM
Have you tried using the Touched event?.
Report Abuse
Paramedic4 is not online. Paramedic4
Joined: 23 Jan 2011
Total Posts: 5934
28 Jun 2014 02:27 AM
I don't think that the Touched event would work for the water terrain and Roblox Lua has the Swimming event to deal with the terrain water. So, is it possible to make the script work even when the player is at idle or floating on the water (The speed will be 0) ?
Report Abuse
AnonyAnonymous is not online. AnonyAnonymous
Joined: 23 Jun 2013
Total Posts: 6332
28 Jun 2014 02:43 AM
Not a solution I can think of at the moment, have you tried increasing the amount of damage done to perhaps something such as 10 to prevent them from just standing still to heal and escape?.
Report Abuse
Paramedic4 is not online. Paramedic4
Joined: 23 Jan 2011
Total Posts: 5934
28 Jun 2014 03:08 AM
Yeah, I have, it did work well :L . I need the script to also deal damage while the player is at idle in the water. Anyone know?
Report Abuse
Paramedic4 is not online. Paramedic4
Joined: 23 Jan 2011
Total Posts: 5934
28 Jun 2014 03:51 AM
Anyone?
Report Abuse
Paramedic4 is not online. Paramedic4
Joined: 23 Jan 2011
Total Posts: 5934
28 Jun 2014 04:56 AM
Please help
Report Abuse
Paramedic4 is not online. Paramedic4
Joined: 23 Jan 2011
Total Posts: 5934
28 Jun 2014 06:03 AM
Help me please!
Report Abuse
Paramedic4 is not online. Paramedic4
Joined: 23 Jan 2011
Total Posts: 5934
28 Jun 2014 08:04 AM
Anyone please?
Report Abuse
Duelingwarlord is not online. Duelingwarlord
Joined: 15 Feb 2010
Total Posts: 22333
28 Jun 2014 08:06 AM
what logic is this?
so when you swim you're automatically drowning??
Report Abuse
Paramedic4 is not online. Paramedic4
Joined: 23 Jan 2011
Total Posts: 5934
28 Jun 2014 08:25 AM
Oh, no, just when you are in the water, but this script doesn't work properly. Anyone know why?
Report Abuse
Paramedic4 is not online. Paramedic4
Joined: 23 Jan 2011
Total Posts: 5934
28 Jun 2014 08:38 PM
Help!
Report Abuse
Paramedic4 is not online. Paramedic4
Joined: 23 Jan 2011
Total Posts: 5934
28 Jun 2014 08:41 PM
Anyone know?
Report Abuse
Paramedic4 is not online. Paramedic4
Joined: 23 Jan 2011
Total Posts: 5934
28 Jun 2014 08:51 PM
Anyone?
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