Problem: I made a Level Up System with Datastore. When I test it in studio it works. When I play the game it won't work! The GUI won't even move and level for the GUI wont change. I'm pretty sure data is saving. This is probably the hardest problem I've come across. If you could help me thank you so much! <3. F.E is on BTW.
Ok this is the Datastore. I didn't make the IntValues inside another IntValue, because I wanted to make a gui level up system.
local LevelStore = game:GetService("DataStoreService"):GetDataStore("LevelUpSystem") game.Players.PlayerAdded:connect(function(player) local Key = "player-"..player.userId local level = Instance.new("IntValue", player) level.Name = "Level" local Exp = Instance.new("IntValue", player) Exp.Name = "EXP" Exp.Changed:connect(function() level.Value = math.floor(Exp.Value / 10) end) local Data = LevelStore:GetAsync(Key) if Data then level.Value = Data[1] Exp.Value = Data[2] else local StuffToSave = {level.Value, Exp.Value} LevelStore:GetAsync(Key, StuffToSave) end end) game.Players.PlayerRemoving:connect(function(player) local Key = "player-"..player.userId local SaveTable = {player.Level.Value, player.EXP.Value} LevelStore:SetAsync(Key, SaveTable) end)
Now let me explain the GUI. The GUI is a green bar that grows every time the EXP[IntValue] changes. Next to the GUI there is another GUI box with a number. That number changes every time the Level[IntValue] changes. The local script's parent is the green bar. This is the GUI script:
local Progress = script.Parent local Player = game.Players.LocalPlayer Player.EXP.Changed:connect(function() Progress.Size = Progress.Size + UDim2.new(0,40,0,0) end) Player.Level.Changed:connect(function() Progress.Size = Progress.Size - UDim2.new(0,360,0,0) script.Parent.Parent.Parent.TextBox.Text = Player.Level.Value end)
Here is the picture for the Level Up GUI: https://gyazo.com/0be27a34ec16a25236beed82df6e04d0 Here is the picture of the StartGUI and Workspace: https://gyazo.com/3fac69907968670815b3ce0398eefed8
As the second script you've shown is a LocalScript, I assume that the script starts running before the values have been added. You probably have to wait until these values get added, using :WaitForChild().
local plrEXP = Player:WaitForChild("EXP") local plrLvl = Player:WaitForChild("Level") plrEXP.Changed:connect(function() Progress.Size = Progress.Size + UDim2.new(0,40,0,0) end) plrLvl.Changed:connect(function() Progress.Size = Progress.Size - UDim2.new(0,360,0,0) script.Parent.Parent.Parent.TextBox.Text = plrLvl.Value -- Also note that dealing with Value objects, you HAVE to put a .Value in the end to get the Value property end)