Why Does This GUI Script Not Work Until I Reset?
The script I have written below is supposed to create an XP bar for the player that automatically updates as the player's XP changes. However, the XP bar does not update unless my player resets; when it respawns, the bar then updates. Is there anything about my script that could be causing this?
001 | Bar 1 = script.Parent.Bar 1 |
002 | PosX 1 = Bar 1. Position.X.Offset |
003 | SizeX 1 = Bar 1. Size.X.Offset |
004 | Bar 2 = script.Parent.Bar 2 |
005 | PosY 2 = Bar 2. Position.Y.Offset |
006 | SizeY 2 = Bar 2. Size.Y.Offset |
007 | Bar 3 = script.Parent.Bar 3 |
008 | PosX 3 = Bar 3. Position.X.Offset |
009 | SizeX 3 = Bar 3. Size.X.Offset |
010 | Bar 4 = script.Parent.Bar 4 |
011 | PosY 4 = Bar 4. Position.Y.Offset |
012 | SizeY 4 = Bar 4. Size.Y.Offset |
013 | Bar 5 = script.Parent.Bar 5 |
014 | PosX 5 = Bar 5. Position.X.Offset |
015 | SizeX 5 = Bar 5. Size.X.Offset |
017 | xp = script.Parent.Parent.Parent.Parent.leaderstats.StatsStorage.XP |
018 | level = script.Parent.Parent.Parent.Parent.leaderstats.Level |
020 | lvlForm = (level.Value* 5 )^ 2 |
023 | ratio 1 = xp.Value/frac 1 |
024 | ratio 2 = xp.Value/(frac 1 +frac 2 ) |
025 | ratio 3 = xp.Value/(frac 1 +frac 2 * 2 ) |
026 | ratio 4 = xp.Value/(frac 1 +frac 2 * 3 ) |
027 | ratio 5 = xp.Value/lvlForm |
031 | if level.Value < 100 then |
033 | Bar 1. Size = UDim 2. new( 0 , SizeX 1 *ratio 1 , 0 , 5 ) |
034 | Bar 1. Position = UDim 2. new( 0 , PosX 1 +( 1 -ratio 1 )/SizeX 1 , 0 , 70 ) |
035 | Bar 2. Size = UDim 2. new( 0 , 5 , 0 , 0 ) |
036 | Bar 2. Position = UDim 2. new( 0 , 70 , 0 , 0 ) |
037 | Bar 3. Size = UDim 2. new( 0 , 0 , 0 , 5 ) |
038 | Bar 3. Position = UDim 2. new( 0 , 0 , 0 , 5 ) |
039 | Bar 4. Size = UDim 2. new( 0 , 5 , 0 , 0 ) |
040 | Bar 4. Position = UDim 2. new( 0 , 0 , 0 , 0 ) |
041 | Bar 5. Size = UDim 2. new( 0 , 0 , 0 , 5 ) |
042 | Bar 5. Position = UDim 2. new( 0 , 0 , 0 , 70 ) |
043 | elseif ratio 1 > = 1 and ratio 2 < 1 then |
044 | Bar 1. Size = UDim 2. new( 0 , 37 , 0 , 5 ) |
045 | Bar 1. Position = UDim 2. new( 0 , 38 , 0 , 70 ) |
046 | Bar 2. Size = UDim 2. new( 0 , 5 , 0 , SizeY 2 *ratio 2 ) |
047 | Bar 2. Position = UDim 2. new( 0 , 70 , 0 , PosY 2 +( 1 -ratio 2 )/SizeY 2 ) |
048 | Bar 3. Size = UDim 2. new( 0 , 0 , 0 , 5 ) |
049 | Bar 3. Position = UDim 2. new( 0 , 0 , 0 , 5 ) |
050 | Bar 4. Size = UDim 2. new( 0 , 5 , 0 , 0 ) |
051 | Bar 4. Position = UDim 2. new( 0 , 0 , 0 , 0 ) |
052 | Bar 5. Size = UDim 2. new( 0 , 0 , 0 , 5 ) |
053 | Bar 5. Position = UDim 2. new( 0 , 0 , 0 , 70 ) |
054 | elseif ratio 1 > = 1 and ratio 2 > = 1 and ratio 3 < 1 then |
055 | Bar 1. Size = UDim 2. new( 0 , 37 , 0 , 5 ) |
056 | Bar 1. Position = UDim 2. new( 0 , 38 , 0 , 70 ) |
057 | Bar 2. Size = UDim 2. new( 0 , 5 , 0 , - 70 ) |
058 | Bar 2. Position = UDim 2. new( 0 , 70 , 0 , 70 ) |
059 | Bar 3. Size = UDim 2. new( 0 , SizeX 3 *ratio 3 , 0 , 5 ) |
060 | Bar 3. Position = UDim 2. new( 0 , PosX 3 +( 1 -ratio 3 )/SizeX 3 , 0 , 0 ) |
061 | Bar 4. Size = UDim 2. new( 0 , 5 , 0 , 0 ) |
062 | Bar 4. Position = UDim 2. new( 0 , 0 , 0 , 0 ) |
063 | Bar 5. Size = UDim 2. new( 0 , 0 , 0 , 5 ) |
064 | Bar 5. Position = UDim 2. new( 0 , 0 , 0 , 70 ) |
065 | elseif ratio 1 > = 1 and ratio 2 > = 1 and ratio 3 > = 1 and ratio 4 < 1 then |
066 | Bar 1. Size = UDim 2. new( 0 , 37 , 0 , 5 ) |
067 | Bar 1. Position = UDim 2. new( 0 , 38 , 0 , 70 ) |
068 | Bar 2. Size = UDim 2. new( 0 , 5 , 0 , - 70 ) |
069 | Bar 2. Position = UDim 2. new( 0 , 70 , 0 , 70 ) |
070 | Bar 3. Size = UDim 2. new( 0 , - 70 , 0 , 5 ) |
071 | Bar 3. Position = UDim 2. new( 0 , 70 , 0 , 0 ) |
072 | Bar 4. Size = UDim 2. new( 0 , 5 , 0 , SizeY 4 *ratio 4 ) |
073 | Bar 4. Position = UDim 2. new( 0 , 0 , 0 , PosY 4 +( 1 -ratio 4 )/SizeY 4 ) |
074 | Bar 5. Size = UDim 2. new( 0 , 0 , 0 , 5 ) |
075 | Bar 5. Position = UDim 2. new( 0 , 0 , 0 , 70 ) |
076 | elseif ratio 1 > = 1 and ratio 2 > = 1 and ratio 3 > = 1 and ratio 4 > = 1 and ratio 5 < 1 then |
077 | Bar 1. Size = UDim 2. new( 0 , 37 , 0 , 5 ) |
078 | Bar 1. Position = UDim 2. new( 0 , 38 , 0 , 70 ) |
079 | Bar 2. Size = UDim 2. new( 0 , 5 , 0 , - 70 ) |
080 | Bar 2. Position = UDim 2. new( 0 , 70 , 0 , 70 ) |
081 | Bar 3. Size = UDim 2. new( 0 , - 70 , 0 , 5 ) |
082 | Bar 3. Position = UDim 2. new( 0 , 70 , 0 , 0 ) |
083 | Bar 4. Size = UDim 2. new( 0 , 5 , 0 , 70 ) |
084 | Bar 4. Position = UDim 2. new( 0 , 0 , 0 , 5 ) |
085 | Bar 5. Size = UDim 2. new( 0 , SizeX 5 *ratio 5 , 0 , 5 ) |
086 | Bar 5. Position = UDim 2. new( 0 , PosX 5 +( 1 -ratio 5 )/SizeX 5 , 0 , 70 ) |
087 | elseif ratio 1 > = 1 and ratio 2 > = 1 and ratio 3 > = 1 and ratio 4 > = 1 and ratio 5 > = 1 then |
088 | Bar 1. Size = UDim 2. new( 0 , 37 , 0 , 5 ) |
089 | Bar 1. Position = UDim 2. new( 0 , 38 , 0 , 70 ) |
090 | Bar 2. Size = UDim 2. new( 0 , 5 , 0 , - 70 ) |
091 | Bar 2. Position = UDim 2. new( 0 , 70 , 0 , 70 ) |
092 | Bar 3. Size = UDim 2. new( 0 , - 70 , 0 , 5 ) |
093 | Bar 3. Position = UDim 2. new( 0 , 70 , 0 , 0 ) |
094 | Bar 4. Size = UDim 2. new( 0 , 5 , 0 , 70 ) |
095 | Bar 4. Position = UDim 2. new( 0 , 0 , 0 , 5 ) |
096 | Bar 5. Size = UDim 2. new( 0 , 38 , 0 , 5 ) |
097 | Bar 5. Position = UDim 2. new( 0 , 5 , 0 , 70 ) |
098 | elseif level.Value > = 100 then |
100 | Bar 1. Size = UDim 2. new( 0 , 37 , 0 , 5 ) |
101 | Bar 1. Position = UDim 2. new( 0 , 38 , 0 , 70 ) |
103 | Bar 2. Size = UDim 2. new( 0 , 5 , 0 , - 70 ) |
104 | Bar 2. Position = UDim 2. new( 0 , 70 , 0 , 70 ) |
106 | Bar 3. Size = UDim 2. new( 0 , - 70 , 0 , 5 ) |
107 | Bar 3. Position = UDim 2. new( 0 , 70 , 0 , 0 ) |
109 | Bar 4. Size = UDim 2. new( 0 , 5 , 0 , 70 ) |
110 | Bar 4. Position = UDim 2. new( 0 , 0 , 0 , 5 ) |
112 | Bar 5. Size = UDim 2. new( 0 , 38 , 0 , 5 ) |
113 | Bar 5. Position = UDim 2. new( 0 , 5 , 0 , 70 ) |