Unable to cast value to std::string - trying to encode and decode a table

I am trying to encode and decode a table using JSONEncode and JSONDecode.

It doesn’t error when I encode it but it does when I try to decode it. It says
Unable to cast value to std::string

Why is it saying this, and how do I successfully decode the data?
Here is the code:

game:GetService("ReplicatedStorage").modcall.OnServerEvent:Connect(function(Player)
	if Player.Name == "MrSprinkleToes" then
		local data = {
			name = Player.Name,
			id = game.JobId
		}
		local enc = game:GetService("HttpService"):JSONEncode(data)
		game:GetService("MessagingService"):PublishAsync("Modcall",enc)
	end
end)

game:GetService("MessagingService"):SubscribeAsync("Modcall",function(data)
	local unenc = game:GetService("HttpService"):JSONDecode(data)
	print(unenc.name)
	print(unenc.id)
end)

It errors at the line that says

local unenc = game:GetService("HttpService"):JSONDecode(data)

MessagingService sends a lua table containing the time at which the data was sent, and the data itself.

Check line 13.

game:GetService("ReplicatedStorage").modcall.OnServerEvent:Connect(function(Player)
	if Player.Name == "MrSprinkleToes" then
		local data = {
			name = Player.Name,
			id = game.JobId
		}
		local enc = game:GetService("HttpService"):JSONEncode(data)
		game:GetService("MessagingService"):PublishAsync("Modcall",enc)
	end
end)

game:GetService("MessagingService"):SubscribeAsync("Modcall",function(data)
	local unenc = game:GetService("HttpService"):JSONDecode(data.Data) --Here
	print(unenc.name)
	print(unenc.id)
end)
1 Like

Ah, thank you! I didn’t know that about MessagingService, that clears it up.