I am making a game, and I need a health bar to lower when the player gets damaged. The code I've been trying is:
local Frame = script.Parent.Frame.Frame local player = game.Players.LocalPlayer.Character player:WaitForChild("Humanoid"):GetPropertyChangedSignal("Health"):Connect(function() Frame.Size.X.Offset = player.Humanoid.Health*3.45 end)
It doesn't work, if you have a solution, I would be glad if you shared it with me, Thanks in advance.
Hello, Ghost40Z!
You can use Health/MaxHealth
and set the result as the frame scale, remember to have the frame parented to another frame or gui object, so the scale max will be the parent's size
local Frame = script.Parent.Frame.Frame local player = game.Players.LocalPlayer.Character player:WaitForChild("Humanoid"):GetPropertyChangedSignal("Health"):Connect(function() Frame.Size = UDim2.new(player.Humanoid.Health/player.Humanoid.MaxHealth, 0, 1, 0) -- This division will aways give a number between 0 and 1, so we know the percent of players health end)