Datastore not working

Hello so im trying to save the values in startergui

Im making crafting system but the only thing left is saving them

I have 2 values that i want to save

its Completed(boolvalue) and Added(Int value)

However when i try to save it wont work like it just doesnt save

It wont say any errors.

1 Like

Hello there, would you mind sending the save and load script(s)?

1 Like
local CraftingDatastore = game:GetService("DataStoreService"):GetDataStore("Crafting")
-- toxic
local function save(plr)
	local Added = plr.PlayerGui.CraftingUI.Main:FindFirstChild("ToxicGlove").Rarities:FindFirstChild("Toxic").Added
	local Completed = plr.PlayerGui.CraftingUI.Main:FindFirstChild("ToxicGlove").Rarities:FindFirstChild("Toxic").Completed

	print(Added.Value)
	print(Completed.Value)

	local ToxicDataFolder = {}
	ToxicDataFolder["Added"] = Added.Value
	ToxicDataFolder["Completed"] = Completed.Value
	local success,errorMsg = pcall(function()
		CraftingDatastore:SetAsync(plr.UserId,ToxicDataFolder)
	end)
	if success then
		print("Data saved!")
	else
		print("There was an error while saving data")
		warn(errorMsg)
	end
end

local function load(plr)
	local Added = plr.PlayerGui.CraftingUI.Main:FindFirstChild("ToxicGlove").Rarities:FindFirstChild("Toxic").Added
	local Completed = plr.PlayerGui.CraftingUI.Main:FindFirstChild("ToxicGlove").Rarities:FindFirstChild("Toxic").Completed

	print(Added.Value)
	print(Completed.Value)

	local data = CraftingDatastore:GetAsync(plr.UserId)
	if data then
		Added.Value = data["Added"]
		Completed.Value = data["Completed"]
	else
		print("No data exists/New player")
		return
	end
end


game.Players.PlayerAdded:Connect(function(plr)

load(plr)
end)


game:BindToClose(function()
	
	

	for _, plr in pairs(game.Players:GetPlayers()) do
		save(plr)
		end
	end)

you cant access client ui elements from server if client manages them on their side

so is it impossible to save then?

no, you just have to have the values on the server already, either send them by a remoteevent if its a simple value, but if its a save its better you handle this on the server already so you cant exploit it

well im adding the value in server using remotes already

then use the values in server, instead of from client UI and itll be fine