I’m scripting a health bar for an enemy in a game, but when I change the health the gui size & text doesn’t change. There are no errors, and the script is pretty simple.
Script: (Server script)
local text = script.Parent.Parent:WaitForChild("HealthbarText")
local hum = text.Parent.Parent.Parent:WaitForChild("Humanoid")
text.Text = hum.Health .. "/" .. hum.MaxHealth
script.Parent.Size = UDim2.new(hum.Health/hum.MaxHealth, 0, 1, 0)
local runService = game:GetService("RunService")
hum:GetPropertyChangedSignal("Health"):Connect(function()
script.Parent.Size = UDim2.new(hum.Health/hum.MaxHealth, 0, 1, 0)
text.Text = hum.Health .. "/" .. hum.MaxHealth
end)
hum:GetPropertyChangedSignal("Health"):Connect(function()
script.Parent.Size = UDim2.new(hum.Health/hum.MaxHealth, 0, 1, 0)
text.Text = hum.Health .. "/" .. hum.MaxHealth
end)
Gettuse
(Midtes)
November 4, 2021, 4:18am
#2
I’d use the hum.HealthChanged function instead of GetPropertyChangedSignal
local text = script.Parent.Parent:WaitForChild("HealthbarText")
local hum = text.Parent.Parent.Parent:WaitForChild("Humanoid")
text.Text = hum.Health .. "/" .. hum.MaxHealth
script.Parent.Size = UDim2.new(hum.Health/hum.MaxHealth, 0, 1, 0)
local runService = game:GetService("RunService")
hum.HealthChanged:Connect(function()
script.Parent.Size = UDim2.new(hum.Health/hum.MaxHealth, 0, 1, 0)
text.Text = hum.Health .. "/" .. hum.MaxHealth
end)
1 Like
Edited my code, but still doesn’t work. Do you know why?
That’s like my script, but with tweening (Which I don’t want). I don’t understand how this helps me (I tried resizing using UDim2.toScale)
Gettuse
(Midtes)
November 4, 2021, 4:37am
#6
You can adjust the length of tween and make it play the Tween animation fast. You can play around with the value until you get what you’re looking for.
Just to clarify you’re handling this on the server right?
1 Like
Yes, I’m doing this on the server.
I made the speed extremely fast (0.0000000000000000001) but it still doesn’t work.
Here’s a place file with only the block containing the health bar
Healthbar.rbxl (40.0 KB)
fungi3432
(fungi3432)
November 4, 2021, 5:21am
#11
I tested the place and changed the humanoid’s health and everything seemed to work properly. Are you sure you’re making the initial health change on the server?
I changed it on the client. When I changed it on the server it worked Thanks!