Help! My Datastore isn't saving

Hi, I was trying to make an in-game settings and make it save so you don’t have to re-do it again. But it didn’t save at all.

Made a button inside PlayerGui, One is a No button and One is Yes.
Here the script for both of them.

--yes-button
local Storage = game:GetService("ReplicatedStorage")
local RE = Storage:FindFirstChild("ShadowsDisabled")
local player = game.Players.LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
	RE:FireServer(player)
end)
--no-button
local Storage = game:GetService("ReplicatedStorage")
local RE = Storage:FindFirstChild("ShadowsEnabled")
local player = game.Players.LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
	RE:FireServer(player)
end)

And this is the datastore script in SSS

local ds  = game:GetService("DataStoreService"):GetDataStore("Test")
local Sere = game.ReplicatedStorage.ShadowsEnabled
local sere = game.ReplicatedStorage.ShadowsDisabled
game.Players.PlayerAdded:Connect(function(plr)
	local folder = Instance.new("Folder", plr)
	folder.Name =  "TestA"

	local val = Instance.new("IntValue", folder)
	val.Name = "ShadowsEnabled"

	local stats = ds:GetAsync(plr)

	if stats ~= nil then
		val.Value = stats[1]
	else
		val.Value =  1
	end
end)

game.Players.PlayerRemoving:Connect(function(plr)
	local save = { }

	table.insert(save, plr.TestA.ShadowsEnabled.Value)

	ds:UpdateAsync(plr.UserId, save)
end)
Sere.OnServerEvent:Connect(function(plr)
	plr.TestA.ShadowsEnabled.Value = 1
end)
sere.OnServerEvent:Connect(function(plr)
	plr.TestA.ShadowsEnabled.Value = 0
end)

I didn’t test the data inside of the studio but did it on Roblox.

1 Like

Use “tostring()” on the key. Strings are used as keys in SetAsync and GetAsync (as well as UpdateAsync and IncrementAsync, and so on). The value, on the other hand, can be any type of Variant.

local ds  = game:GetService("DataStoreService"):GetDataStore("Test")
local Sere = game.ReplicatedStorage.ShadowsEnabled
local sere = game.ReplicatedStorage.ShadowsDisabled
game.Players.PlayerAdded:Connect(function(plr)
	local folder = Instance.new("Folder", plr)
	folder.Name =  "TestA"

	local val = Instance.new("IntValue", folder)
	val.Name = "ShadowsEnabled"

	local stats = ds:GetAsync(tostring(Player.UserId))

	if stats ~= nil then
		val.Value = stats[1]
	else
		val.Value =  1
	end
end)

game.Players.PlayerRemoving:Connect(function(plr)
	local save = { }

	table.insert(save, plr.TestA.ShadowsEnabled.Value)

	ds:UpdateAsync(plr.UserId, save)
end)
Sere.OnServerEvent:Connect(function(plr)
	plr.TestA.ShadowsEnabled.Value = 1
end)
sere.OnServerEvent:Connect(function(plr)
	plr.TestA.ShadowsEnabled.Value = 0
end)
1 Like

Doesn’t work, Did I make it wrong?

local ds  = game:GetService("DataStoreService"):GetDataStore("Test")
local Sere = game.ReplicatedStorage.ShadowsEnabled
local sere = game.ReplicatedStorage.ShadowsDisabled
game.Players.PlayerAdded:Connect(function(plr)
	local folder = Instance.new("Folder", plr)
	folder.Name =  "TestA"

	local val = Instance.new("IntValue", folder)
	val.Name = "ShadowsEnabled"

	local stats = ds:GetAsync(tostring(plr.UserId))

	if stats ~= nil then
		val.Value = stats[1]
	else
		val.Value =  1
	end
end)

game.Players.PlayerRemoving:Connect(function(plr)
	local save = { }

	table.insert(save, plr.TestA.ShadowsEnabled.Value)

	ds:SetAsync(tostring(plr.UserId, save))
end)
Sere.OnServerEvent:Connect(function(plr)
	plr.TestA.ShadowsEnabled.Value = 1
end)
sere.OnServerEvent:Connect(function(plr)
	plr.TestA.ShadowsEnabled.Value = 0
end)

Actually it isn’t because of that, let me recheck your script.

1 Like

Upon checking the code with a mate, the code seems fine, you just need to make sure you publish and test it in the actual game. DS doesn’t work when testing in Studio.

I didn’t test it on studio, But how did it work on yours?

I didn’t test it, but based on the code, it appears to be fine; I also double-checked with a friend; did you try it in the game?

Yes I did, I even tested it on my Alts

You checked and it still doesn’t work?

Yes it doesn’t, should I send the game file to you?

I gonna send it anyways
Test.rbxl (39.0 KB)

ds:SetAsync(tostring(plr.UserId), save)

Try this, in the code you sent you inserted “save” inside the tostring arguments, even though tostring only takes up one argument.

1 Like

Yes! It works now! Thank you for helping me. :hugs:

1 Like