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 » Scripters
Home Search
 

Re: Sword Healing Script [Help]

Previous Thread :: Next Thread 
elitesoldier5555 is online. elitesoldier5555
Joined: 28 Dec 2011
Total Posts: 19
25 Feb 2017 10:28 PM
Now i got this script to where i am trying to create a sword that heals you when you equip it. It should heal you a certain amount (currently 100) of health every 5 seconds which works fine. It also increases your maximum health (currently 100) when you equip it and removes it when you unequip it. Now my problem is, is that when you equip it then unequip it the healing stays and everytime you equip it back it stacks up. How do i script it to where the moment you unequip the weapon the healing effect goes away, but when you equip it back you gain it back again but should not stack.

Note: the "+1 do -- don't change" i put it into the script so that it can never get to max health because the current max health would be 100 (original hp) + 100 (200 is the new hp) but with a +1 (201 hp) which makes it to where it can't reach it so it continues to heal. (infinite loop).


Tool = script.Parent

Tool.Equipped:connect(function()
Player = script.Parent.Parent
Player.Humanoid.MaxHealth = Player.Humanoid.MaxHealth + 100
while Player.Humanoid.Health < Player.Humanoid.MaxHealth + 1 do -- don't change the + 1
wait(5)
Player.Humanoid.Health = Player.Humanoid.Health + 100
end
end)

Tool.Unequipped:connect(function()
Player.Humanoid.MaxHealth = Player.Humanoid.MaxHealth -100
end)
Report Abuse
Lua_Basics is not online. Lua_Basics
Joined: 04 Jun 2012
Total Posts: 9977
25 Feb 2017 10:42 PM
if equipped then SO: Player = game:GetPlayerFromCharacter(script.Parent.Parent) --I'd personally not ## ## this way local Tool = script.Parent local equipped = false Tool.Equipped:connect(function() equipped = true if Player and equipped then Player.Humanoid.MaxHealth = Player.Humanoid.MaxHealth + 100 while Player.Humanoid.Health < Player.Humanoid.MaxHealth + 1 do -- don't change the + 1 wait(5) Player.Humanoid.Health = Player.Humanoid.Health + 100 end end end) Tool.Unequipped:connect(function() equipped = false Player.Humanoid.MaxHealth = Player.Humanoid.MaxHealth -100 end)
Report Abuse
Lua_Basics is not online. Lua_Basics
Joined: 04 Jun 2012
Total Posts: 9977
25 Feb 2017 10:43 PM
I did what I can but roblox's filter and forum stink A LOT.
Report Abuse
elitesoldier5555 is online. elitesoldier5555
Joined: 28 Dec 2011
Total Posts: 19
25 Feb 2017 11:04 PM
thx i will try it out!
Report Abuse
elitesoldier5555 is online. elitesoldier5555
Joined: 28 Dec 2011
Total Posts: 19
25 Feb 2017 11:14 PM
btw what does the "SO" stand for?
Report Abuse
elitesoldier5555 is online. elitesoldier5555
Joined: 28 Dec 2011
Total Posts: 19
25 Feb 2017 11:27 PM
it doesn't work. :/
Report Abuse
Lecturous is not online. Lecturous
Joined: 17 Aug 2013
Total Posts: 1096
25 Feb 2017 11:43 PM
see if this works:

Tool = script.Parent
Player = script.Parent.Parent
local prevHealth = Player.Humanoid.MaxHealth
local healing = false

Tool.Equipped:connect(function()
healing = true
Player.Humanoid.MaxHealth = prevHealth + 100
while Player.Humanoid.Health < Player.Humanoid.MaxHealth + 1 and healing do -- don't change the + 1
wait(5)
Player.Humanoid.Health = Player.Humanoid.Health + 100
end
end)

Tool.Unequipped:connect(function()
healing = false
Player.Humanoid.MaxHealth = prevHealth
end)


Report Abuse
elitesoldier5555 is online. elitesoldier5555
Joined: 28 Dec 2011
Total Posts: 19
26 Feb 2017 10:45 AM
i'll try it thanks! :D
Report Abuse
elitesoldier5555 is online. elitesoldier5555
Joined: 28 Dec 2011
Total Posts: 19
26 Feb 2017 10:53 AM
i don't think it works, the problem with my script is that the healing stacks or does not get removed the moment you unequip the sword. what if it is a function and then when you unequip you can set the function to false or something i don't really know, i am a noob at scripting XD.
Report Abuse
elitesoldier5555 is online. elitesoldier5555
Joined: 28 Dec 2011
Total Posts: 19
27 Feb 2017 08:25 AM
bump
Report Abuse
elitesoldier5555 is online. elitesoldier5555
Joined: 28 Dec 2011
Total Posts: 19
01 Mar 2017 09:39 PM
bump
Report Abuse
elitesoldier5555 is online. elitesoldier5555
Joined: 28 Dec 2011
Total Posts: 19
01 Mar 2017 09:39 PM
bumpity bump
Report Abuse
XxAwesomeGamerDudexX is not online. XxAwesomeGamerDudexX
Joined: 02 Oct 2014
Total Posts: 14
04 Aug 2017 03:34 PM
I have a similar problem but I can't script at all so I would like to see the end result so maybe I could add a script into my gear and it would work.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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