hello there, I’m have a script for the heal system but the script isn’t truly work by read the script that I have display under this, in the print(“click”) it say the script ended there and cant continue the script, I don’t really know what wrong but I think I was cuz by the local to find the player humanoid. Here the script.
local healthPack = script.Parent
local healAmount = 30
local cooldown = 10
print("start")
healthPack.ClickDetector.MouseClick:Connect(function(plr)
print("click")-- the script stop here it wont go or print
local player = game.Players.PlayerAdded
local char = player.Character or player.CharacterAdded
local humanoid:Humanoid = player.Character or player.CharacterAdded:WaitForChild("Humanoid")
local maxhp = humanoid.MaxHealth
print("player data")
local canheal = humanoid.Health < maxhp
local cantheal = humanoid.Health >= maxhp
print("going to heal player")
if plr and canheal then
humanoid.Health = humanoid.Health + healAmount
repeat until
humanoid.Health + healAmount
print("finish heal")
end
end)
if want further info to help fix this, I gradually tell you.
I’m not sure why you made a second variable to the player? Just switch all of the 'player’s to ‘plr’
local healthPack = script.Parent
local healAmount = 30
local cooldown = 10
print("start")
healthPack.ClickDetector.MouseClick:Connect(function(plr)
print("click")-- the script stop here it wont go or print
local char = plr.Character or plr.CharacterAdded
local humanoid:Humanoid = plr.Character or plr.CharacterAdded:WaitForChild("Humanoid")
local maxhp = humanoid.MaxHealth
print("player data")
local canheal = humanoid.Health < maxhp
local cantheal = humanoid.Health >= maxhp
print("going to heal player")
if plr and canheal then
humanoid.Health = humanoid.Health + healAmount
repeat until
humanoid.Health + healAmount
print("finish heal")
end
end)
cantheal was never used, plus canheal already checks if the health is less than MaxHealth.
And also, if you didn’t know, Humanoid.Health can never be more than its MaxHealth. If it is, then it will automatically set the health to max health.
healthPack.ClickDetector.MouseClick:Connect(function(plr)
print("click")-- the script stop here it wont go or print
local player = game.Players.PlayerAdded
local char = plr.Character or plr.CharacterAdded
local humanoid:Humanoid = plr.Character:WaitForChild("Humanoid")
print("going to heal player")
if plr then
humanoid.Health = humanoid.Health + healAmount
end
end)
healthPack.ClickDetector.MouseClick:Connect(function(plr)
print("click")
local humanoid:Humanoid = plr.Character and char:FindFirstChild("Humanoid")
print(humanoid)
if humanoid then
print("healing")
humanoid.Health = humanoid.Health + healAmount
print("healed")
end
end)