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

Making a health bar in a test game. I've tried for hours to fix it, but nothing works?

Asked by 4 years ago

I have been working on this script for a while, and it is very bug. If anyone can, help refine it while you help answer this question.

I am trying to make a health check to make sure the health bar I'm making is working properly. If it is not, the health check will correct it. here is the health check portion. I'm still not sure exactly what to do, so it is unfinished.

local Dummy = game.Workspace.Dummy
local hp = Dummy.Humanoid
if game.Workspace.Dummy.Health -- INSERT FIX OR SOMETHING HERE
then


    function newHealth()
        script.Parent:TweenSize(UDim2.new(0,647,0,70))
        script.Parent:TweenSize(UDim2.new(newHealth/500,0,1,0),Enum.EasingDirection.Out,Enum.EasingStyle.Quad,0.15)
        script.Parent:TweenSize(UDim2.new(newHealth/300,0,1,0),Enum.EasingDirection.Out,Enum.EasingStyle.Quad,0.15) 
    end
end

Here is the rest of the code in case you need it.

wait (.1)
function reDummy ()
    local z = game.Workspace.Dummy

local backup = z:clone()

    wait(5)
    if z.Humanoid.Health == 0 then
        z:Remove()
        wait(6)
        backup.Parent = game.Workspace
        backup.Head:MakeJoints()
        backup.Torso:MakeJoints()
    end
    if z == nil then
        wait(9)
        backup.Parent = game.Workspace
        backup.Head:MakeJoints()
        backup.Torso:MakeJoints()
    end 
end

    local visible = script.Parent.Parent.Parent.Visible 
    local bframe = script.Parent.Parent.Parent.Parent
    while true do
        local Dummy = game.Workspace.Dummy
        local hp = Dummy.Humanoid


    script.Parent:TweenSize(UDim2.new(hp,0,1,0),Enum.EasingDirection.Out,Enum.EasingStyle.Quad,0.15)
    wait (0.1)
    local hp = Dummy.Humanoid.Health
    if hp < 0.001 or hp == 0 then
    print "it died"
        bframe.BaseFrame.Visible = false
    wait (7)

Dummy.Humanoid.HealthChanged:Connect(function(newHealth)
        script.Parent:TweenSize(UDim2.new(0,647,0,70))
        script.Parent:TweenSize(UDim2.new(newHealth/500,0,1,0),Enum.EasingDirection.Out,Enum.EasingStyle.Quad,0.15)
        script.Parent:TweenSize(UDim2.new(newHealth/300,0,1,0),Enum.EasingDirection.Out,Enum.EasingStyle.Quad,0.15)
    end)
        bframe.BaseFrame.Visible = true
            script.Parent:TweenSize(UDim2.new(0,647,0,70))
            script.Parent:TweenSize(UDim2.new(hp,0,1,0),Enum.EasingDirection.Out,Enum.EasingStyle.Quad,0.15)
            local hp = game.Workspace:WaitForChild("Dummy").Humanoid.Health/300
            script.Parent:TweenSize(UDim2.new(hp,0,1,0),Enum.EasingDirection.Out,Enum.EasingStyle.Quad,0.15)
        end
        wait (.2)
    end
0
Is there any error? If so, what is it? SaltyIceberg 81 — 4y
0
in line 3 you need to add Dummy.Humanoid.Health and not Dummy.Health (Also, specify your issue, we can not do this for you) Sergio4755 21 — 4y

Answer this question