:JSONEncode/Decode error?

Background:

Using OOP, I create a dictionary whenever someone creates a server in my game, passing through the following variables:

image

which is fine and dandy, however, I wish to pass this onto the client whenever a new player joins the game, to show all the available servers, and I do this as follows:

First I use OOP to create a dictionary called “Server” and I name it after the user’s ID :
Example: Server[1234567] is basically Data[1234567] in a more common sense except each client gets a different dictionary. Simple enough. This all works.

The part that breaks is when I new player joins I have this function:

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

	for i,v in pairs(Server) do
		local Table = HTTP:JSONEncode(Server[i])

		RE:FireClient(plr,nil,"PlayerJoined",nil,nil,Table)
		print(i)
	end
end)

In which fires over a JSON encrypted table, cool, it prints the users id afterward. When I Collect it on the server, I Decode it -

		local Dictionary = HTTP:JSONDecode(JSON)
		local Player = Dictionary["Player"]
		local Password = Dictionary.Password
		
		print(Player)

(JSON being the sent over table)

Player in this case prints nil. This is the error and I have no idea why it does this.

TD;LR: Used OOP, Set a dictionary to the players User Id, Encrypted it with JSONEncode, sent to the client, error occurs.

If anyone can help me out that would be great thanks!

1 Like

Is Player in your module.new constructor an actual Player Instance? If so, Instances cannot be serialized through JSON

1 Like

Ooof yea I pass over the character object for the [“Player”] variable, I think that might be my issue then.

1 Like