Alright I made a MedKit. Strange thing is, it works when I test it in ROBLOX Studio, but when I play the actual game, the medkit does not work. It is composed of a Tool named Medical Kit, a Union inside named Handle, and a Script named MedKitScript. It is a normal script.
01 | local tool = script.Parent |
02 | local healValue = 50 |
03 | local canHeal = true |
04 |
05 |
06 |
07 |
08 | tool.Equipped:connect( function (mouse) |
09 | mouse.Button 1 Down:connect( function () |
10 | local humanoid = tool.Parent.Humanoid |
11 | if humanoid and canHeal then |
12 | canHeal = false |
13 | local currentHealth = humanoid.Health |
14 | local newHealth = currentHealth + healValue |
15 | humanoid.Health = newHealth |
The mouse can only be accessed from the client I think. My guess to solving this problem is instead using tool.Activated, in which it fires every time the players activates the tool:
01 | local tool = script.Parent |
02 | local healValue = 50 |
03 | local canHeal = true |
04 |
05 |
06 |
07 |
08 | tool.Activated:connect( function () |
09 | local humanoid = tool.Parent.Humanoid |
10 | if humanoid and canHeal then |
11 | canHeal = false |
12 | local currentHealth = humanoid.Health |
13 | local newHealth = currentHealth + healValue |
14 | humanoid.Health = newHealth |
15 | wait( 2 ) |
16 | tool:Destroy() |
17 | end |
18 | end ) |