Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

DataStore + text not in sync? [SOLVED BUT NO ANSWER]

Asked by 8 years ago

So I have this DataStore script, and there's no errors, but it doesn't what your balance is in the gui

for _, player in ipairs(game.Players:GetPlayers()) do
  local username = "user_"..player.userId
  local ds = game:GetService("DataStoreService"):GetDataStore("Points")
  local points = ds:GetAsync(username)

  local text = player.PlayerGui.CoinGui.Frame.TextLabel 
  if username == "user_33666287" then
    ds:UpdateAsync(username, function(add)
      return 100000
    end)
  elseif points == 0 or points == nil then
    ds:UpdateAsync(username, function(add)
      return 50
    end)
  end

  local function update() 
    text.Text = "Coins : ".. ds:GetAsync(username)
  end

  ds:OnUpdate(username,update)
  update()
end

Adark fixed it! all that changed was this

for _, player in ipairs(game.Players:GetPlayers()) do

to this

game.Players.PlayerAdded:connect(function(player)

Answer this question