I have been trying to fix this bug for well over an hour and I am completely stumped. (Its probably something silly breaking it) The problem is on line 8 with the playerHumanoid parameter from function. The error is: Players.Its4Realzies.Backpack.Blessed Medkit.HealScript:8: attempt to index nil with ‘Name’
Tool = script.Parent
–Heal function for both user and most hurt teammate
local function healPlayer(playerHumanoid, healAmount)
local healthAdded = 0
print(playerHumanoid.Name)
local healParticle = script.HealEffects:Clone()
healParticle.Enabled = true
healParticle.Parent = playerHumanoid.Parent.Torso
repeat
if playerHumanoid.MaxHealth <= playerHumanoid.Health + healAmount/10 then
playerHumanoid.Health = playerHumanoid.maxHealth
else
playerHumanoid.Health = playerHumanoid.Health + healAmount/10
healthAdded = healthAdded + healAmount/10
end
wait(0.1)
until healthAdded >= healAmount or playerHumanoid.Health == playerHumanoid.maxHealth
healParticle.Enabled = false
end
function Heal()
--Play sound
Tool.Handle.Fire.PlayOnRemove = true
Tool.Handle.Fire:Destroy()
local localPlayer = game:GetService("Players").LocalPlayer
--Heals user
local human = localPlayer.Character:FindFirstChild("Humanoid")
if (human ~= nil) then
healPlayer(human, 100)
end
local mostInjuredHealth = 100
local mostInjuredHumanoid = nil
--Find most injured teammate
for _,v in pairs(game.Players:GetChildren()) do
if v.Character ~= nil and v.TeamColor == localPlayer.TeamColor and 0 < v.Character.Humanoid.Health and v.Character.Humanoid.Health < mostInjuredHealth then
mostInjuredHealth = v.Character.Humanoid.Health
mostInjuredHumanoid = v.Character:FindFirstChild("Humanoid")
end
end
--Heal most injured teammate
healPlayer(mostInjuredHumanoid, 100)
--Destroys tool mesh
if workspace:FindFirstChild(Tool.PlayerNameValue.Value) ~= nil then
workspace:FindFirstChild(Tool.PlayerNameValue.Value):destroy()
end
--Destroys Tool
Tool.Parent = nil
end
function onActivated()
if not Tool.Enabled then
return
end
Tool.Enabled = false
Heal()
end
script.Parent.Activated:connect(onActivated)