Thanks for the help everyone. I appreciate you more than you know.
I have a working healing potion script. It heals 50 health. The player health goes up, then drops back down to where it was during the natural health regeneration. If I remove the natural health regeneration script, the healing potion works fine. I would like them both to work, but they seem to be conflicting.
Here are the scripts.
Healing potion
local CanActivate = true
local player = game.Players.LocalPlayer
local character = player.Character
script.Parent.Activated:connect(function()
if CanActivate == true then
CanActivate = false
local animation = character.Humanoid:LoadAnimation(script.Parent.Animation)
animation:Play()
wait()
character.Humanoid.Health = character.Humanoid.Health + 50
local particles = script.Parent.Particles:Clone()
particles.Parent = player.Character.Head
particles.Enabled = true
wait(1)
particles.Enabled = false
wait(10)
CanActivate = true
particles:Destroy()
end
end)
And here is the natural health regeneration script.
local self = script.Parent
local Humanoid = self:WaitForChild("Humanoid")
local Regen = false
Humanoid.HealthChanged:connect(function()
if (not Regen and Humanoid.Health > 0) then
Regen = true
while (Humanoid.MaxHealth > Humanoid.Health) do
local NewHealth = Humanoid.Health + (Humanoid.Health/Humanoid.MaxHealth) + .5
Humanoid.Health = NewHealth
wait(Humanoid.Health/Humanoid.MaxHealth * 2)
end
if (Humanoid.MaxHealth < Humanoid.Health) then
Humanoid.Health = Humanoid.MaxHealth
end
Regen = false
end
end)
script.Parent.HealthScript.HealthUpdate:FireClient(script.Parent.HealthScript)
that health regen script is roblox’s default health regen script. It has a deprecated connect. I also thought that was strange.
Also I tried a different approach. I tried to disable the health regen script for 1 seconds during the potion drink and made a more simple script to test it. But I cant get the script to disable because I am not using the correct string.
health is the script name that is under parent, but it is giving an error.
local tool = script.Parent
tool.Activated:Connect(function()
local Humanoid = tool.Parent:FindFirstChild('Humanoid')
script.Parent.Health.Disabled = true -- health is the script name that is under Parent.
Humanoid.Health = Humanoid.Health + 50
wait(1)
script.Parent.Health.Disabled = false
end)
the script regen name is health, How do I disable it for a short time.
How about using attributes? When drinking the potion, give an attribute to the player, maybe “NoHealing” then remove it when the drinking is finished.
if (not Regen and Humanoid.Health > 0 and Humanoid:GetAttribute("NoHealing") == nil) then
script.Parent.Activated:connect(function()
if CanActivate == true then
CanActivate = false
local animation = character.Humanoid:LoadAnimation(script.Parent.Animation)
animation:Play()
wait()
character.Humanoid:SetAttribute("NoHealing", true) -- set attribute
character.Humanoid.Health = character.Humanoid.Health + 50
character.Humanoid:SetAttribute("NoHealing", nil) -- remove attribute
local particles = script.Parent.Particles:Clone()
particles.Parent = player.Character.Head
particles.Enabled = true
wait(1)
particles.Enabled = false
wait(10)
CanActivate = true
particles:Destroy()
end
end)
You can also use an instance, such as a BoolValue, if you prefer.