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

What is wrong with my Exp Bar script?

Asked by 10 years ago

I've got this Exp bar script that I've been working on, but it simply doesn't work. No error in the output or anything, it just doesn't run. It is in a Local Script, and I know that the Hierarchy is right as well. What is wrong here?

wait(2)

local xps = {0, 3, 6, 10, 15, 20, 25, 30, 40, 50,
    65, 80, 95, 110, 125, 140, 155, 180, 210,
    250, 300, 350, 400, 450, 500, 575, 650, 725,
    825, 1000};

function hudsize()
    local Player = game.Players.LocalPlayer
    local level = Player.leaderstats.Level.Value
    local ExpBar = script.Parent.ExpBar
    local xp = Player.Exp.Value
    local level = Player.leaderstats.Level.Value
    for level = 1, #xps do

        local required = ((xps[level] * 100)/xp)
        wait(.1)
        local size = (required * 200)
        wait(.1)
        ExpBar.Size = UDim2.new(0,15,0,size)
        print(Player.Name.."'s ExpBar Size is "..size)

        end
    end

game.Players.PlayerAdded:connect(hudsize)
game.Players.LocalPlayer.Exp.Changed:connect(hudsize)

0
And it's not disabled? emite1000 335 — 10y
0
Nope, not disabled. SlickPwner 534 — 10y
0
You don't need the PlayerAdded event. LocalScripts run as soon as the player joins. GoldenPhysics 474 — 10y
0
The PlayerAdded event doesn't fire at all in LocalScripts, actually. adark 5487 — 10y

1 answer

Log in to vote
1
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
10 years ago

PlayerAdded doesn't fire for LocalScripts, for some reason. Just use ChildAdded instead (and if needed, check that new children actually are Player instances)

Most likely that is your problem.

0
I used game.Players.ChildAdded instead of PlayerAdded, but it didn't work. Still no errors in the output either. SlickPwner 534 — 10y
0
You know this only updates the EXP bar whenever another player joins the game? BlueTaslem 18071 — 10y
0
How would I make it otherwise? SlickPwner 534 — 10y
0
`while wait(1) do hudsize(); end` BlueTaslem 18071 — 10y
0
Okay, that worked, but if I use, for example, Kohl's Admin commands to change the value of my Exp, the bar continually grows PAST 200 (its max size) until it reaches 20,000, then it restarts from 0 and grows back to 20,000, etc. SlickPwner 534 — 10y
Ad

Answer this question