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)