local Money = game:GetService("DataStoreService"):GetDataStore("Money") game:GetService("Players").PlayerAdded:connect(function(plyr) local bank = "user_"..plyr.userId --Using the player's name glitches out somehow. while wait(180) do if plyr.PlayerGui.MoneyGui:WaitForChild("Money") then plyr.PlayerGui.MoneyGui.Money.Text = "$"..tostring(plyr.PlayerGui.MoneyGui.Money.Text:sub(2)+5) end end wait(.5) plyr.PlayerGui.MoneyGui.Money.Text = Money:GetAsync(bank) print("Loaded Your Money") plyr.CharacterAdded:connect(function(char) wait(.5) char.Humanoid.Died:connect(function() Money:SetAsync(bank, plyr.PlayerGui.MoneyGui.Money.Text) print("Saved Your Money") end) plyr.PlayerGui.MoneyGui.Money.Text = Money:GetAsync(bank) print("Loaded Your Money") end) plyr.PlayerGui.MoneyGui.Money.Changed:connect(function() Money:SetAsync(bank, plyr.PlayerGui.MoneyGui.Money.Text) print("Saved Your Money") end) end)
It won't print anything or save anything. When I reset my character , the gui doesn't change to the amount of money you have saved. Please help!
It's because you put an infinite loop halfway through the script... When you put:
while wait(180) do ... end
You basically make it so every 180 seconds ...
happens.. which breaks the script. Nothing after that code will be executed.
To fix this, you can move that loop to the bottom of the script (before the last end)
) or use a separate thread for it.