Help with tweenservice error

I Tried to make a heart beat change speed depending on the characters health.
Every time I run it, it stays on the same speed of the heartbeat

I Tried changing a lot of stuff in my script and nothing have helped.

Heres the script (located in StarterCharacterScripts)

local char = script.Parent
local h = char.Humanoid
local p = game.Players:GetPlayerFromCharacter(script.Parent)
local gui = p.PlayerGui["HealthGui"]
local heart = gui.Heart
local heart2 = gui.Heart2

local ti 

local tw = game:GetService("TweenService")
local dest = {}
dest.Size = UDim2.new(0, 207,0, 212)
dest.Position = UDim2.new(0.82, 0, 0.698, 0)
ti = TweenInfo.new(1.3,Enum.EasingStyle.Elastic,Enum.EasingDirection.InOut,3,true,0)
local fin = tw:Create(heart,ti,dest)

--local tw1 = game:GetService("TweenService")
--local dest1 = {}
--dest.Size = UDim2.new(0, 207,0, 212)
--dest.Position = UDim2.new(0.82, 0, 0.698, 0)
--local ti1 = TweenInfo.new(0.1,Enum.EasingStyle.Elastic,Enum.EasingDirection.InOut,math.huge,true,0)
--local fin1 = tw:Create(heart2,ti1,dest1)

gui.TextLabel.Text = 100
gui.Heart2.Visible = false
gui.Heart.Visible = true
if h.Health >= 100 then
	gui.Heart2.Visible = false
	gui.Heart.Visible = true
	fin:Play()
end

if h.Health <= 25 then
	gui.Heart2.Visible = true
	gui.Heart.Visible = false
ti = TweenInfo.new(0.4,Enum.EasingStyle.Elastic,Enum.EasingDirection.InOut,3,true,0)
	fin:Play()
	print("Health is under 25")
end

h.HealthChanged:Connect(function()
	gui.TextLabel.Text = math.floor(h.Health)
end)

Can anybody help me with this?

I Still haven’t found a solution for it.

Maybe also try to reset the “fin”. It still uses the old TweenInfo in my guess.

With GUIs you can use :TweenSize or :TweenPosition.

This is not completely correct. You can also use the TweenService for this.

I Am going to try that right now

The main thing is that this line:

if h.Health <= 25 then
	--gui.Heart2.Visible = true
	--gui.Heart.Visible = false)
	fin = tw:Create(heart,ti2,dest)
	fin:Play()
	print("Health is under 25")
end

does not print “Health is under 25”

But this one:

if h.Health >= 100 then
	--gui.Heart2.Visible = false
	--gui.Heart.Visible = true
	print("Health is 100")
	fin:Play()
end

Does print health is 100

This is your problem, this is the ONLY code that runs.image

And that’s why it prints your health is 100, as your deafult health is 100, and it only checks it once.

You could use a changed function for the health and customize based on what the health is on how fast it beats.

How does it control the other script?

So you mean it only checks up on the regular beat on the 100 health one?

What do you mean other scripts?

If you are talking about how to solve this then this would be your answer:

h.HealthChanged:Connect(function()
	gui.TextLabel.Text = math.floor(h.Health)
        if h.Health <= 25 then
	    gui.Heart2.Visible = true
	    gui.Heart.Visible = false
            ti = TweenInfo.new(0.4,Enum.EasingStyle.Elastic,Enum.EasingDirection.InOut,3,true,0)
	    fin:Play()
	    print("Health is under 25")
       end
end)

Now going to quickly explain it, you only check it when the script starts.
The version i provided is whenever it’s health is changed.

That’s really your only problem, you do not run that check when the health is property is changed, but rather on the start of the script.

By “Other scripts” i meant the rest of the script, my bad.

It wont impact it, the only problem is why it isnt working is because you check it
Once. And that is at the start of the script
Put your code in the HealthChanged event.
(I seriously hope i am understanding your question right.)

GuiObject:TweenPosition(), GuiObject:TweenSize(), and GuiObject:TweenSizeAndPosition() exists, here’s a link with more information:
GuiObject | Documentation - Roblox Creator Hub (take a look at functions)
hope this helped!