Use should use :GetService whenever referencing a service, so it should be game:GetService("Players").
All of the {""} should be "", and Color = {""} should be Color = {}, and currency should likely be defined inside the .PlayerAdded function.
You are doing 3 separate :GetAsync calls, which are HTTP requests and have rate limits and are not very fast. You should instead do a :GetAsync call once and store it’s result in the table. Also, because you are saving a dictionary ds:GetAsync(plr.UserId) with return a dictionary, and so it will error when you try and set current.Name or the others using it.
Generally, there is no point in doing this, but you shouldn’t use wait (use task.wait instead) and the task.wait should be inside the loop, with the top being while true do instead because while wait() do is not how while loops are meant to be used.
You should wrap all :GetAsync and :SetAsync in pcalls because they can error, like so:
local Success, Info = pcall(function()
return ds:GetAsync(plr.UserId)
end)
if not Success then
warn("An error occurred! Error: " .. Info)
else
currency = Info
end
Here is the script with some of this implemented:
local dsService = game:GetService("DataStoreService")
local ds = dsService:GetDataStore("BusinessDatastore")
local Players = game:GetService("Players")
local playerCurrencies = {}
Players.PlayerAdded:Connect(function(plr)
playerCurrencies[plr] = ds:GetAsync(plr.UserId)
if not playerCurrencies[plr] then
playerCurrencies[plr] = {
Name = "DefaultName",
Description = "DefaultDescription",
Color = {0, 0, 0}
}
end
currency = playerCurrencies[plr]
game:GetService("ReplicatedStorage").SaveMoneyEvent.OnServerEvent:Connect(function()
ds:SetAsync(plr.UserId, currency)
end)
while true do
ds:SetAsync(plr.UserId, currency)
currency.Name = script.Parent.NameValue.Value
currency.Description = script.Parent.Description.Value
currency.Color = script.Parent.Color.Value
print(currency)
task.wait(10)
end
end)
Players.PlayerRemoving:Connect(function(plr)
ds:SetAsync(plr.UserId, currency)
end)
Can you show a picture of the data you are trying to save? I think it may contain illegal characters (non UTF-8) which the datastore cannot save without extra steps.