Is there something with my script?

I am currently making a health hi system for a game I am working on and it doesn’t work… no errors nothing and I am pretty sure my script is made right.

Local script:

local ts = game:GetService("TweenService")
local Player = game.Players.LocalPlayer
local Character = Player.Character
local Humanoid = Character:WaitForChild("Humanoid")
local MainUI = script.Parent
local Bar = MainUI.Bar
local TextLabel = MainUI.HealthValue

TextLabel.Text = math.floor(Humanoid.Health).. "/".. math.floor(Humanoid.MaxHealth)

Humanoid.HealthChanged:Connect(function(health)
	TextLabel.Text = math.floor(health).. "/".. math.floor(Humanoid.MaxHealth)
	Bar:TweenSize(UDim2.new(math.floor(health)/Humanoid.MaxHealth, 0, Bar.Size.Y.Scale, 0))
end)
1 Like

set the time for the tween?________

2 Likes
local ts = game:GetService("TweenService")
local Player = game.Players.LocalPlayer
local Character = Player.Character
local Humanoid = Character:WaitForChild("Humanoid")
local MainUI = script.Parent
local Bar:Frame = MainUI.Bar
local TextLabel = MainUI.HealthValue

local TIME = 1

TextLabel.Text = math.floor(Humanoid.Health).. "/".. math.floor(Humanoid.MaxHealth)

Humanoid.HealthChanged:Connect(function(health)
	TextLabel.Text = math.floor(health).. "/".. math.floor(Humanoid.MaxHealth)
	Bar:TweenSize(UDim2.new(math.floor(health)/Humanoid.MaxHealth, 0, Bar.Size.Y.Scale, 0), Enum.EasingDirection.In, Enum.EasingStyle.Linear, TIME)
end)
2 Likes

Doesn’t work… unsure why it doesn’t work.

1 Like

here’s a health bar I made a bit ago, I’ve tested it and it works fine.
Could you try modifying it for whatever you need?
healthbar.rbxm (6.6 KB)

1 Like

What exactly is it that isn’t working? What do you expect it to do, and what part of that seems to be failing?

1 Like

I modified it a bit, and it should work!

local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local MainUI = script.Parent
local Bar = MainUI.Bar
local fill = Bar.fill
local TextLabel = Bar.HealthValue

local TIME = 1

local function changehealth(health, maxhealth)
	TextLabel.Text = health .. "/".. maxhealth
	fill:TweenSize(UDim2.new(health / maxhealth, 0, 1, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Quint, TIME)
end
changehealth(math.floor(Humanoid.Health), math.floor(Humanoid.MaxHealth))

Humanoid.HealthChanged:Connect(function(health)
	changehealth(math.floor(Humanoid.Health), math.floor(Humanoid.MaxHealth))
end)

The fill size is {0, 0},{1, 0}
and healthvalue size is {1, 0},{1, 0}
healthvalue Zindex should be higher than fill’s Zindex (and make sure backgroundtransparency is 1)

And this is where it needs to go

image

1 Like

In these situations, you should show what the explorer structure is, where the script it, what kind of script it is, and if you changed it, what RunContext does the script use

1 Like

The same issue that I have been having is still there.

https://gyazo.com/b24a36261b61247c7686667a5b35c9aa

Layout
HealthFrame is the Bar
Bar is fill
then you have the HealthValue
image

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.