This weird error appears on in the output

output: argument 2 missing or nil.

it does not give me any error on the script analysis but only the output.

litterally the line that the output says argument 2 missing or nil:


DSS:GetDataStore("Text"):SetAsync(game.Workspace.Globe.SurfaceGui.TextLabel.Text, Text)

I don’t see any missing argument.

That means Text is nil, you can verify this by printing it beforehand.

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”.

1 Like


my full script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local GlobalText = ReplicatedStorage:WaitForChild("GlobalText")
local DSS = game:GetService("DataStoreService")


GlobalText.OnServerEvent:Connect(function(blabla, Text)
	DSS:GetDataStore("Text"):SetAsync(game.Workspace.Globe.SurfaceGui.TextLabel.Text, Text)
	game.Workspace.Globe.SurfaceGui.TextLabel.Text = DSS:GetDataStore("Text"):GetAsync(game.Workspace.Globe.SurfaceGui.TextLabel.Text)
end)

why player user id? It’s a text that everyone should see it. not just one single player’s data.

I believe the text of that textbox is what they intended to use for the key, the issue is that the second argument Text is a reference to a nil value.

no!
I made a game where you type your code in the textbox and execute it in the past. And it was 100% working.

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)

what is saved text?
did you define it?

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?

this was just an example.

i actually found out why!

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.