Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why is my custom health GUI doing this?

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

✓ Accepted answer

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


2 comments

0

Oh okay! I didn't know that. Thanks!

0

Your welcome

This discussion is preserved as it was. New answers, comments, and votes are closed.