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

[Solved]Health Bar X Size getting bigger then Screen?

Asked by 4 years ago
Edited 4 years ago

Hello everyone,

i have a problem with my screen bar if the player life is getting higher(power value = maxhealth+powervalue) then my health bar is sizing to much (Screen Shot) maybe someone see the error or soluation ?

local Players = game:GetService("Players")
local player = Players.LocalPlayer or Players:GetPropertyChangedSignal("LocalPlayer"):wait()
local character = player.Character or player.CharacterAdded:wait()

local PlayerLevel = player:WaitForChild("leaderstats").Level.Value
local human = character:FindFirstChild("Humanoid")
local health = human.Health
local maxhealth = human.MaxHealth
local PlayerXP = player:WaitForChild("playerdata"):WaitForChild("XP")

local xpToLevelUp = function(level)
    return 100 + level * 5
end

while wait() do
    local pourcentage = math.floor(player:WaitForChild("playerdata"):WaitForChild("XP").Value/xpToLevelUp(player:WaitForChild("leaderstats"):WaitForChild("Level").Value) * 100)
    if health then
        script.Parent:TweenSize(UDim2.new(player:WaitForChild("playerdata"):WaitForChild("XP").Value/xpToLevelUp(player:WaitForChild("leaderstats"):WaitForChild("Level").Value), 0, 1, 0))
        script.Parent.Parent.TextLabel.Text = pourcentage.. "%"
    end
end

Screenshot

i already tryed something like that

    if health == maxhealth or health > maxhealth then
        script.Parent.Size = UDim2.new(1, 0,1, 0)
    end
0
ok i can tell you the issue right now, dont use offset in the sizing, only use scale or it will go outside the frame Gameplayer365247v2 1055 — 4y
0
hes right exobyteXL 290 — 4y
0
He's not using Offset he's using Scale zemljorog 80 — 4y

1 answer

Log in to vote
2
Answered by 4 years ago

The problem here is you're not checking if the size is greater than the maximum. When using Scale, you want to make sure its not going above 1, or

local xSize = player:WaitForChild("playerdata"):WaitForChild("XP").Value/xpToLevelUp(player:WaitForChild("leaderstats"):WaitForChild("Level").Value)
--If the size is greater than 1, just set it to 1
script.Parent:TweenSize(UDim2.new((xSize < 1 and xSize) or 1, 0, 1, 0))
0
this Work so far but i don't know why if i get over 8100 MaxHealth the game put it back to 8100 Ravage1337 35 — 4y
0
So I think if you wanted their health bars to be the same without it having a lot of issues you can take the damage that you are losing and set it as a percentage to the health they have. Then use that percentage against the scale of 1. So if I had 650/890 health I would set that goal percentage and then tween it to the percentage since scale of 1 is technically 100% SethHeinzman 284 — 4y
0
Thank you @zemljorog forgot to answer works fine i just posted the experience script and not the health one hehehe :) just had to change xSize Health/MaxHealth thank you for the help Ravage1337 35 — 4y
Ad

Answer this question