DataStore script not saving data, and not loading correctly

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I am trying to create a DataStore script to save and load admin’s data when they join for BanGUI.

  2. What is the issue? Include screenshots / videos if possible!
    The script will not save. The player history is loaded, but the text is in quotes that I would like to remove. The font does not load at all.

DataStore script:

local dataStore = game:GetService("DataStoreService"):GetDataStore("BanGUI-Data")
local function save(player)
	local success, err = pcall(function()
		local key = "banGuiKey--" ..player.UserId
		local dataToSave = {
			{
				player.PlayerGui.banGUI.MenuContent.Main.SettingsFrame.FontSelection.FontValue.Value
			},
			{
				player.PlayerGui.banGUI.MenuContent.Main.HistoryFrame.HistoryList.Box1.Text,
				player.PlayerGui.banGUI.MenuContent.Main.HistoryFrame.HistoryList.Box2.Text,
				player.PlayerGui.banGUI.MenuContent.Main.HistoryFrame.HistoryList.Box3.Text,
				player.PlayerGui.banGUI.MenuContent.Main.HistoryFrame.HistoryList.Box4.Text,
				player.PlayerGui.banGUI.MenuContent.Main.HistoryFrame.HistoryList.Box5.Text,
				player.PlayerGui.banGUI.MenuContent.Main.HistoryFrame.HistoryList.Box6.Text,
				player.PlayerGui.banGUI.MenuContent.Main.HistoryFrame.HistoryList.Box7.Text,
				player.PlayerGui.banGUI.MenuContent.Main.HistoryFrame.HistoryList.Box8.Text,
				player.PlayerGui.banGUI.MenuContent.Main.HistoryFrame.HistoryList.Box9.Text,
				player.PlayerGui.banGUI.MenuContent.Main.HistoryFrame.HistoryList.Box10.Text
			}
		}
		dataStore:SetAsync(key,dataToSave)
	end)
	if success then
		print("BanGUI data saved!")
	else
		print("Failed to save BanGUI data! " ..err)
	end
end

local function load(player)
	local success, err = pcall(function()
		repeat wait() until player.PlayerGui:FindFirstChild("banGUI")
		local key = "banGuiKey--" ..player.UserId
		local dataToLoad = dataStore:GetAsync(key)
		if dataToLoad then
			local settingsData, history = table.unpack(dataToLoad)
			local fontSelection = table.unpack(settingsData)
			local history1,history2,history3,history4,history5,history6,history7,history8,history9,history10 = table.unpack(history)
			for _, object in pairs(player.PlayerGui.banGUI.MenuContent.Main.HistoryFrame.HistoryList:GetChildren()) do
				if object.Name == "Box1" then
					object.Text = history1
				elseif object.Name == "Box2" then
					object.Text = history2
				elseif object.Name == "Box3" then
					object.Text = history3
				elseif object.Name == "Box4" then
					object.Text = history4
				elseif object.Name == "Box5" then
					object.Text = history5
				elseif object.Name == "Box6" then
					object.Text = history6
				elseif object.Name == "Box7" then
					object.Text = history7
				elseif object.Name == "Box8" then
					object.Text = history8
				elseif object.Name == "Box9" then
					object.Text = history9
				elseif object.Name == "Box10" then
					object.Text = history10
				end
			end
			player.PlayerGui.banGUI.MenuContent.Main.SettingsFrame.FontSelection.FontValue.Value = fontSelection
		end
	end)
	if success then
		print("BanGUI data loaded!")
	else
		print("Error loading BanGUI data! " ..err)
	end
end

game.Players.PlayerAdded:Connect(function(plr)
	if workspace["BanGUI By Dude8074"].Admins:FindFirstChild(plr.UserId) then
		load(plr)
	end
end)
game.Players.PlayerRemoving:Connect(function(plr)
	if workspace["BanGUI By Dude8074"].Admins:FindFirstChild(plr.UserId) then
		save(plr)
	end
end)
game:BindToClose(function()
	for _, plr in pairs(game.Players:GetPlayers()) do
		if workspace["BanGUI By Dude8074"].Admins:FindFirstChild(plr.UserId) then
			save(plr)
		end
	end
end)

font loading script:

local code = script.Parent.Parent.Code
local titilliumWeb = script.Parent.Parent.TitilliumWeb
local gothamBlack = script.Parent.Parent.GothamBlack
local fredokaOne = script.Parent.Parent.FredokaOne

local function updateFont()
	if script.Parent.Value == "TitilliumWeb" then
		code.Text = "Code"
		gothamBlack.Text = "GothamBlack"
		fredokaOne.Text = "FredokaOne"
		
		for _, object in pairs(script.Parent.Parent.Parent.Parent.Parent.Parent:GetDescendants()) do
			if object:IsA("TextButton") or object:IsA("TextLabel") or object:IsA("TextBox") then
				object.Font = Enum.Font.TitilliumWeb
			end
		end
		titilliumWeb.Text = "<b><i>TitilliumWeb</i></b>"
	elseif script.Parent.Value == "Code" then
		titilliumWeb.Text = "TitilliumWeb"
		gothamBlack.Text = "GothamBlack"
		fredokaOne.Text = "FredokaOne"
		
		for _, object in pairs(script.Parent.Parent.Parent.Parent.Parent.Parent:GetDescendants()) do
			if object:IsA("TextButton") or object:IsA("TextLabel") or object:IsA("TextBox") then
				object.Font = Enum.Font.Code
			end
		end
		code.Text = "<b><i>Code</i></b>"
	elseif script.Parent.Value == "FredokaOne" then
		titilliumWeb.Text = "TitilliumWeb"
		gothamBlack.Text = "GothamBlack"
		code.Text = "Code"
		
		for _, object in pairs(script.Parent.Parent.Parent.Parent.Parent.Parent:GetDescendants()) do
			if object:IsA("TextButton") or object:IsA("TextLabel") or object:IsA("TextBox") then
				object.Font = Enum.Font.FredokaOne
			end
		end
		fredokaOne.Text = "<b><i>FredokaOne</i></b>"
	elseif script.Parent.Value == "GothamBlack" then
		titilliumWeb.Text = "TitilliumWeb"
		code.Text = "Code"
		fredokaOne.Text = "FredokaOne"
		
		for _, object in pairs(script.Parent.Parent.Parent.Parent.Parent.Parent:GetDescendants()) do
			if object:IsA("TextButton") or object:IsA("TextLabel") or object:IsA("TextBox") then
				object.Font = Enum.Font.GothamBlack
			end
		end
		gothamBlack.Text = "<b><i>GothamBlack</i></b>"
	end
end

wait()
updateFont()

script.Parent.Changed:Connect(function()
	updateFont()
end)
1 Like

Can you show me a screenshot as I don’t get what you mean by “text in quotes”.

Screen Shot 2021-05-30 at 12.57.26 PM
this is what it comes out as, it should be: No history yet!

Well I’ll look into the code. :face_with_raised_eyebrow:

I’m new to coding so this MIGHT take a while…

Check the text, have you accidentally added quotes?

No. The text is a string, so it automatically adds quotes.

Have you implemented a string value as a replacement?

Maybe you need to leave it how it is

I don’t really see a problem when it has quotes.

If you need to replicate all of the stuff in this to see the issue, it’s all in my development build: