[SOLVED] Datastore is always nil, no matter what I do

EDIT: I finally got it working

Hi devs,

I have a problem where the datastore data will always come back as nil.
I’ve made a separate game to test, and it’s still nil. I don’t know why.

This is what I have in a script: (The data variable is the text of a gui, which is not nil. The issue is the datastore, not anything else. I am getting the “data is nil” print.)

game.ReplicatedStorage.SaveAndLoadData.OnServerEvent:Connect(function(plr, saveOrLoad, data)
	if saveOrLoad == "save" then
		local sucess, errormessage = pcall(function()
			dataStore:SetAsync(plr.UserId, data)
		end)
	else
		if data ~= nil then
			print(dataStore:GetAsync(plr.UserId))
			game.ReplicatedStorage.SaveAndLoadData:FireClient(plr, dataStore:GetAsync(plr.UserId))
		else
			print("data is nil")
		end
	end
end)

I know you didn’t ask for this but I recommend it’s not a ReplicatedStorage remote because exploiters can spam fire it and break the queue (not sure if it applies to everyone)

1 Like