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!

4 comments
It doesn't "break" the script, else the "while" loop will not run at all. Rather, the thread is stuck in the loop forever.
I would have to do a spawn function. mkay thx. It's supposed to loop infinitely.
you could create a coroutine for the while loop
@Lord @Future That's what I meant when saying "use a seperate thread". The Spawn function creates a new thread, and so do coroutines.