Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

All healthbar scripts being buggy and wont work?

Asked by 3 years ago

Every healthbar script i try works fine for the most part, but when i die it doesnt go back to full size when i respawn. It's gotten to the point where im just looking at scripts online and they all still do that

this is the current script im using

-- ScriptGuider
-- Basic custom health bar program from my YouTube video
-- Video: https://www.youtube.com/watch?v=opZtUhwDWE8
wait() -- ROBLOX made me do this.

local Player = game:GetService'Players'.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:wait()
local Human = Character:WaitForChild("Humanoid")

local HealthFrame = script.Parent

Human.HealthChanged:connect(function(Health)
    HealthFrame.Size = UDim2.new(Health/Human.MaxHealth,0,1,0)
end)
0
although i am new at scripting, maybe you should try to reset the health bar when the humanoid is dead, it could go into StarterCharacterScripts, although im not sure if it will work JaydenLegenderyDude 22 — 3y
0
believe it or not this worked DraconianSG 58 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

it seems that you set the screengui ResetOnSpawn to false that makes the script stop working, try to put the character inside a loop like this or you can set it to true instead

local HealthFrame = script.Parent
local Player = game.Players.LocalPlayer

while wait(0.2) do
    local Character = Player.Character or Player.CharacterAdded:wait()
    local Human = Character:FindFirstChild("Humanoid")
    if Human then
        local Health = Human.Health
        HealthFrame.Size = UDim2.new(Health/Human.MaxHealth,0,1,0)
    end
end
0
You are right, i had it set not to reset on spawn because there is another part of the hud that needs to stay as it is after death and i always have the HUD in one screengui so i didnt realise DraconianSG 58 — 3y
Ad

Answer this question