My health GUI script wont work as intended, this is my first time scripting with GUI so im not really supprised, but heres the script
Code
local player = game:GetService("Players").LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")
local GUI = script.Parent
hum.HealthChanged:Connect(function(dmg)
GUI.Size = UDim2.new(0, dmg / hum.MaxHealth, 0, 24)
end)
Im not sure why its doing that, help and feedback would be appreciated
Switch the GUI.Size to change the Scale of the UI, not the offset.
local player = game:GetService("Players").LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")
local GUI = script.Parent
hum.HealthChanged:Connect(function(dmg)
GUI.Size = UDim2.new(dmg / hum.MaxHealth, 0, 0, 24)
end)
local player = game:GetService("Players").LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")
local GUI = script.Parent
hum.HealthChanged:Connect(function(dmg)
GUI.Size = UDim2.new(dmg / hum.MaxHealth, 244, 0, 30)
end)
You have 2 problems with this code. You’re only decreasing the bar by the damage dealt but not the current health the player has, which is what you’re going for. You’re also using both an Offset and Scale value which makes the bar resize out of the frame it’s located in.
Change this line: