Is this a datastorage issue or a coding issue?

The part of the module script that contains the function

function module.UILog()
	local success, currentNumber = pcall(function()
		return commandDataStore:GetAsync(numberKey)
	end)

	local number = tonumber(currentNumber) or 1
	print("Number of logs to display:", number)

	for i = 1, number do
		local success, logData = pcall(function()
			return commandDataStore:GetAsync(i)
		end)
		if success then
			local mod = logData.Mod
			local punishment = logData.Punishment
			game.ReplicatedStorage.AdminSystem.SC:FireAllClients(tostring(i),logData,mod,punishment)
		end
		wait(0.3)
	end
end

The localscript:

game.ReplicatedStorage.AdminSystem.SC.OnClientEvent:Connect(function(number,logData,mod,cmd)
	print("thx!! "..tostring(logData))
	local frame = script.Parent:Clone()
	frame.Parent = script.Parent.Parent
	frame.case.Text = "Case Number "..number
	frame.mod.Text = mod or "N/A"

	if cmd then
		if cmd == "warn" or cmd == "punish" or cmd == "warning" then
			frame.punishment.Text = "Warning"
			frame.punishment.TextColor3 = Color3.fromRGB(255, 255, 0)
		elseif cmd == "kick" then
			frame.punishment.Text = "Kick"
			frame.punishment.TextColor3 = Color3.fromRGB(255, 170, 0)
		elseif cmd == "Ban" then
			frame.punishment.Text = "Ban"
			frame.punishment.TextColor3 = Color3.fromRGB(255, 0, 0)
		else
			frame.punishment.Text = string.upper(string.sub(cmd, 1, 1))
		end
	else
		frame.punishment.Text = "N/A"
	end
end)

In the console it will tell me thx!! {"Cmd":"punish","Mod":"Dacatboy_YT","Users":["Dacatboy_YT"],"Time":1708228372,"Reason":"test"} - Client - LocalScript:2
I’m confused, because my text labels give N/A instead of the correct value that is needed. Been trying to solve for 5 hours. And when I log them, it gives me nil

Thank you!!

Instead of just saying else, use elseif to write exactly what the condition is.

That isn’t the issue though…The issue is the fact that when I try to retrieve the data from the log it gives nil

Try this and let me know if it fixes your issue of returning nil.

function module.UILog()
	local success, currentNumber = pcall(function()
		return commandDataStore:GetAsync(numberKey)
	end)

	local number = tonumber(currentNumber) or 1
	print("Number of logs to display:", number)

	for i = 1, number do
		local success, logData = pcall(function()
			return commandDataStore:GetAsync(i)
		end)
		if success then
			local mod = logData.Mod
			local punishment = logData.Cmd
			game.ReplicatedStorage.AdminSystem.SC:FireAllClients(tostring(i),logData,mod,punishment)
		end
		wait(0.3)
	end
end

Still returns nil.

You’d want to make sure logData exists along side the pcall returning success

if success and logData then