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

Why won't my UDim2 Script tween based on player EXP?


P = script.Parent.Parent.Parent.Parent

P.leaderstats.EXP.Changed:connect(function()
    if P.leaderstats.EXP > (P.leaderstats.MaxEXP) then
        P.leaderstats.Level.Value = P.leaderstats.LastLevel.Value + 1
        P.leaderstats.EXP.Value = 0
        P.leaderstats.MaxEXP.Value = P.leaderstats.Level.Value * 59


local PositionX = script.Parent.Position.X.Offset
local initX = script.Parent.Size.X.Offset

while true do 
wait()
local EXP = script.Parent.Parent.Parent.Parent.Parent.leaderstats.EXP.Value
local EXPMax = script.Parent.Parent.Parent.Parent.Parent.leaderstats.Level.Value * 59
local Pie = (EXP / EXPMax) --Missed Scale 
--script.Parent.Size = UDim2.new( 0, initX*Pie, 0, 30) 
script.Parent:TweenSize(UDim2.new(0, initX*Pie, 0, 30),"Out","Sine",0.25)
end 

1 comment

0

Thanks. I found out why it didnt work, in line 17 I wrote "local Pie = (EXP / EXPMAX)" when it should have been "local Pie= (EXP / MaxEXP)"

2 answers

✓ Accepted answer

The script isn't working because the TweenSize command only occurs if EXP > MaxEXP (at which point EXP is reset anyway). After the first level is achieved, the script will appear to start working.

However, you are starting a new infinite loop every time EXP > MaxEXP. Instead, either take the while loop out of the "Changed" function (ex add an 'end' statement on lines 8 and 9), or else move the contents of the while loop into the function (but don't use a loop).

This may be why it is not working but I carnet test it.

This may result in a float e.g 1.3442:-

local Pie = (EXP / EXPMax) 

The offset value must be in an Integer Click Here

1 comment

0

The offset is automatically converted into an integer; giving it a float will not cause an error.

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