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

Why is my custom health GUI doing this?

Asked by 9 years ago

Hello! I am making a health gui simulating the one form 2011! It looks perfect except for the scripting. The script is simple though looks complicated. If the players health is above 75% the health bar4 will be full. If the health is above 50 but below 75 the health bar will be more than half full etc. I have the script inserted into the player and that works fine but when I enter the game the custom health bar instantly resizes it self to {0.0, 0.0} {0.0, 0.0}. I have no idea why it is doing this. Nothing is in the output. Here is the scriptL:

while true do wait()
    if script.Parent.Humanoid.Health >=75 then
        game.Players.LocalPlayer.PlayerGui.HealthGUI.tray.bar.Size = UDim2.new{0.96, 0},{0.83, 0}
    else
        game.Players.LocalPlayer.PlayerGui.HealthGUI.tray.bar.Size = game.Players.LocalPlayer.PlayerGui.HealthGUI.tray.bar.Size

end

    if script.Parent.Humanoid.Health >=50 and script.Parent.Humanoid.Health <= 75 then
        game.Players.LocalPlayer.PlayerGui.HealthGUI.tray.bar.Size = UDim2.new{0.72, 0},{0.83, 0}
    else
        game.Players.LocalPlayer.PlayerGui.HealthGUI.tray.bar.Size = game.Players.LocalPlayer.PlayerGui.HealthGUI.tray.bar.Size

if script.Parent.Humanoid.Health >=25 and script.Parent.Humanoid.Health <= 50 then
        game.Players.LocalPlayer.PlayerGui.HealthGUI.tray.bar.Size = UDim2.new{0.48, 0},{0.83, 0}
    else
        game.Players.LocalPlayer.PlayerGui.HealthGUI.tray.bar.Size = game.Players.LocalPlayer.PlayerGui.HealthGUI.tray.bar.Size

        if script.Parent.Humanoid.Health >=0 and script.Parent.Humanoid.Health <= 25 then
        game.Players.LocalPlayer.PlayerGui.HealthGUI.tray.bar.Size = UDim2.new{0.24, 0},{0.83, 0}
    else
        game.Players.LocalPlayer.PlayerGui.HealthGUI.tray.bar.Size = game.Players.LocalPlayer.PlayerGui.HealthGUI.tray.bar.Size

        if script.Parent.Humanoid.Health == 0 then
        game.Players.LocalPlayer.PlayerGui.HealthGUI.tray.bar.Size = UDim2.new{0.0, 0},{0.83, 0}
    else
        game.Players.LocalPlayer.PlayerGui.HealthGUI.tray.bar.Size = game.Players.LocalPlayer.PlayerGui.HealthGUI.tray.bar.Size

    end
    end
    end
    end
    end

1 answer

Log in to vote
1
Answered by 9 years ago

UDim2 works like this:

ScreenGui.Frame.Size = UDim2(0,100, 0,100)

Like this: (X.Scale, X.Offset, Y.Scale, Y.Offset)

while true do wait()
    if script.Parent.Humanoid.Health >=75 then
        game.Players.LocalPlayer.PlayerGui.HealthGUI.tray.bar.Size = UDim2.new(0.96, 0, 0.83, 0)
    else
        game.Players.LocalPlayer.PlayerGui.HealthGUI.tray.bar.Size = game.Players.LocalPlayer.PlayerGui.HealthGUI.tray.bar.Size

end

    if script.Parent.Humanoid.Health >=50 and script.Parent.Humanoid.Health <= 75 then
        game.Players.LocalPlayer.PlayerGui.HealthGUI.tray.bar.Size = UDim2.new(0.72, 0, 0.83, 0)
    else
        game.Players.LocalPlayer.PlayerGui.HealthGUI.tray.bar.Size = game.Players.LocalPlayer.PlayerGui.HealthGUI.tray.bar.Size

if script.Parent.Humanoid.Health >=25 and script.Parent.Humanoid.Health <= 50 then
        game.Players.LocalPlayer.PlayerGui.HealthGUI.tray.bar.Size = UDim2.new(0.48, 0, 0.83, 0)
    else
        game.Players.LocalPlayer.PlayerGui.HealthGUI.tray.bar.Size = game.Players.LocalPlayer.PlayerGui.HealthGUI.tray.bar.Size

        if script.Parent.Humanoid.Health >=0 and script.Parent.Humanoid.Health <= 25 then
        game.Players.LocalPlayer.PlayerGui.HealthGUI.tray.bar.Size = UDim2.new(0.24, 0, 0.83, 0)
    else
        game.Players.LocalPlayer.PlayerGui.HealthGUI.tray.bar.Size = game.Players.LocalPlayer.PlayerGui.HealthGUI.tray.bar.Size

        if script.Parent.Humanoid.Health == 0 then
        game.Players.LocalPlayer.PlayerGui.HealthGUI.tray.bar.Size = UDim2.new(0.0, 0, 0.83, 0)
    else
        game.Players.LocalPlayer.PlayerGui.HealthGUI.tray.bar.Size = game.Players.LocalPlayer.PlayerGui.HealthGUI.tray.bar.Size

    end
    end
    end
    end
    end


0
Oh okay! I didn't know that. Thanks! minikitkat 687 — 9y
0
Your welcome EzraNehemiah_TF2 3552 — 9y
Ad

Answer this question