Help!
I’m trying to make a potion script, this is what’s already added on the script.
when you click, the anim plays, then the effects apply on you, your health goes to 100.But it isn’t working.
Heres what I want added: When the health applies on you, the tool gets deleted from your inventory, but the health still applies.
Heres the code:
local drinkAnim = script:WaitForChild("DrinkAnimation")
local drinkSound = script:WaitForChild("DrinkSound")
local potion = script.Parent
potion.Activated:Connect(function()
if not potion:FindFirstChild("Contents") then return end
local char = potion.Parent
local humanoid = char:FindFirstChild("Humanoid")
if humanoid then
local loadedAnim = humanoid:LoadAnimation(drinkAnim)
loadedAnim:Play()
drinkSound:Play()
loadedAnim.Stopped:Wait()
potion.Contents:Destroy()
humanoid.Health = 100
end
end
Okay so, the script works and all. But the only thing that doesn’t work is humanoid.health. It doesn’t change my health to 100, it stays the same. Also is there a way to make the tool destroy after the health goes to 100?
Well, deleting the Tool upon activation would be easy enough by doing tool:Destroy()
Maybe you could do a print() check to see if the humanoid’s health has changed? Try this:
local drinkAnim = script:WaitForChild("DrinkAnimation")
local drinkSound = script:WaitForChild("DrinkSound")
local potion = script.Parent
potion.Activated:Connect(function()
if not potion:FindFirstChild("Contents") then return end
local char = potion.Parent
local humanoid = char:FindFirstChild("Humanoid")
if humanoid then
print("Playing Animation")
local loadedAnim = humanoid:LoadAnimation(drinkAnim)
loadedAnim:Play()
drinkSound:Play()
loadedAnim.Stopped:Wait()
print("Humanoid's Health Changed")
humanoid.Health = 100
potion:Destroy()
end
end