01 | local Money = game:GetService( "DataStoreService" ):GetDataStore( "Money" ) |
02 |
03 | game:GetService( "Players" ).PlayerAdded:connect( function (plyr) |
04 | local bank = "user_" ..plyr.userId --Using the player's name glitches out somehow. |
05 | while wait( 180 ) do |
06 | if plyr.PlayerGui.MoneyGui:WaitForChild( "Money" ) then |
07 | plyr.PlayerGui.MoneyGui.Money.Text = "$" .. tostring (plyr.PlayerGui.MoneyGui.Money.Text:sub( 2 )+ 5 ) |
08 | end |
09 | end |
10 | wait(. 5 ) |
11 | plyr.PlayerGui.MoneyGui.Money.Text = Money:GetAsync(bank) |
12 | print ( "Loaded Your Money" ) |
13 | plyr.CharacterAdded:connect( function (char) |
14 | wait(. 5 ) |
15 | char.Humanoid.Died:connect( function () |
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:
1 | while wait( 180 ) do |
2 | ... |
3 | 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.