This is my healthbar's script
game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Health, false) local player = game.Players.LocalPlayer local char = player.Character or player.CharacterAdded:Wait() local healthbar = script.Parent.Frame:WaitForChild("HealthBar") game:GetService("RunService").RenderStepped:Connect(function() local humanoid = char:FindFirstChild("Humanoid") healthbar.Health.Size = UDim2.new(humanoid.Health/humanoid.MaxHealth,0,1,0) end)
When you load in everything is fine but when the player gains more health the gui goes off the screen and the only way i found to fix this is by resetting. When you reset the gui works perfectly.
So what do i have to do to make the gui work as the player gains strength without having to reset
First off, you realllyyy shouldn’t use RenderStepped for this. RenderStepped runs every single frame, which seems a little unnecessary. Instead of RenderStepped, detect the humanoid’s health change. What seems to be your problem is the Humanoid’s health being greater than their MaxHealth (which, may not be your problem since I can’t debug the script right now) because I don’t see anything else wrong here. To fix this, just add a simple check.
game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Health, false) local player = game.Players.LocalPlayer local char = player.Character or player.CharacterAdded:Wait() local humanoid = char:WaitForChild("Humanoid") local healthbar = script.Parent.Frame:WaitForChild("HealthBar") humanoid:GetPropertyChangedSignal("Health"):Connect(function() if humanoid.Health > humanoid.MaxHealth then healthbar.Health.Size = UDim2.new(humanoid.MaxHealth/humanoid.MaxHealth,0,1,0) return end healthbar.Health.Size = UDim2.new(humanoid.Health/humanoid.MaxHealth,0,1,0) end)
I think i kinda figured it out. When a player joined their current health was higher than their max health so the gui was not updated. Now I'm thinking there's something wrong with my health script and im not sure how to fix it.
This is my health script, basically its suppose to give you more health based on your strength value. For example someone with 100 strength will have more health than someone with 20 strength, etc.
local DefaultHealth = 100 game.Players.PlayerAdded:Connect(function(player) local Stats = player:WaitForChild("leaderstats") local Strength = Stats:FindFirstChild("strength") local char = player.Character or player.CharacterAdded:wait() if char then local hum = char:FindFirstChild("Humanoid") if hum then hum.MaxHealth = DefaultHealth * Strength.Value * 1.25 end Strength.Changed:connect(function(value) if player.Character and player.Character:FindFirstChild("Humanoid") then player.Character.Humanoid.MaxHealth = DefaultHealth * Strength.Value * 1.25 end end) end end)
You can try it with 'if'
Put into the function
if Humanoid.Health <= 0 then --if the health from player = 0 then health bar will be resize healthbar.Health.Size = UDim2.new("0,0,1,0) --Set the Bar to end and not out of screen. end
I think that should work :-D