You are missing a key. You can save data on player’s UserId. So it’s gonna be (player.UserId, game.Workspace.Globe.SurfaceGui.TextLabel.Text). Just make sure that you have a variable for “player”.
Since you use :SetAsync and :GetAsync at the same time i would recommend using :UpdateAsync()
This saves and get the value at the same time. (safer)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local GlobalText = ReplicatedStorage:WaitForChild("GlobalText")
local DSS = game:GetService("DataStoreService")
local surfaceText = game.Workspace.Globe.SurfaceGui.TextLabel
local dataStore = DSS:GetDataStore("Text")
GlobalText.OnServerEvent:Connect(function(blabla, Text)
dataStore:UpdateAsync("GlobalText", function(savedText)
surfaceText.Text = savedText or "Empty"
return Text --value to save
end)
end)
but why update async did not work for me and setasync worked for me when:
local DSS = game:GetService("DataStoreService")
local DS = DSS:GetDataStore("Money")
local DS2 = DSS:GetDataStore("Points")
game.Players.PlayerAdded:Connect(function(plr)
local ls = Instance.new("Folder")
ls.Name = "leaderstats"
ls.Parent = plr
local Money = Instance.new("IntValue")
Money.Parent = ls
Money.Name = "Money"
Money.Value = DS:GetAsync(plr.UserId) or 0
local Points = Instance.new("IntValue")
Points.Parent = ls
Points.Name = "Points"
Points.Value = DS2:GetAsync(plr.UserId) or 0
end)
game.Players.PlayerRemoving:Connect(function(plr)
DS:SetAsync(plr.UserId, plr.leaderstats.Money.Value)
DS2:SetAsync(plr.UserId, plr.leaderstats.Points.Value)
end)
game:BindToClose(function()
for i, v in pairs(game.Players:GetPlayers()) do
DS:SetAsync(v.UserId, v.leaderstats.Money.Value)
DS2:SetAsync(v.UserId, v.leaderstats.Points.Value)
end
end)
when i replaced SetAsync With UpdateAsync, data did not save?
it is because The player will be automaticallt sent to the remote event, but in the script tat fires the event, i did, nil, game.Worskpace.Globe.SurfaceGui, etc.