|
| 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 |
|
|
|
| 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 |
|
|
|
| 25 Feb 2017 10:43 PM |
| I did what I can but roblox's filter and forum stink A LOT. |
|
|
| Report Abuse |
|
|
| |
|
|
| 25 Feb 2017 11:14 PM |
| btw what does the "SO" stand for? |
|
|
| Report Abuse |
|
|
| |
|
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 |
|
|
| |
|
|
| 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 |
|
|
| |
|
| |
|
| |
|
|
| 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 |
|
|