I want to do what the title says but all my keys from my table turn into string when I send it to the client through a remote event
And If I print the table I’m trying to send on to the client on the server
Please show us your code, so we can see it and understand how to help you.
_G.ActiveInteractions[Part] = {Actions = {}, MaxZoomDistance = ZoomDistance,MaxActivationDistance = ActivationDistance}
game.ReplicatedStorage.InteractionEvents:WaitForChild("InteractionsUpdated"):FireAllClients(_G.ActiveInteractions)
my friend says
I’m not entirely sure what you’re trying to do, but I’m almost certain there’s a better way.
Perhaps using attributes to store state on the instances you’re trying to pass as keys, and then on the client you could just read what those attributes are set to.
Or, you could just use string keys, or send like the names of the instances to the client instead of the actual instance.
You can convert that table to HttpService:JSONEncode
and HttpService:JSONDecode
.
-- Server script
local http = game:GetService("HttpService")
_G.ActiveInteractions[Part] = {Actions = {}, MaxZoomDistance = ZoomDistance,MaxActivationDistance = ActivationDistance}
local stringTable = http:JSONEncode(_G.ActiveInteractions)
game.ReplicatedStorage.InteractionEvents:WaitForChild("InteractionsUpdated"):FireAllClients(stringTable)
-- Local script
local http = game:GetService("HttpService")
local event = game.ReplicatedStorage.InteractionEvents:WaitForChild("InteractionsUpdated")
event.onClientEvent:Connect(function(stringTable)
local tablee = http:JSONDecode(stringTable)
print(tablee)
end)
Whoever your friend is, have 0 knowledge about parameters
They don’t change into strings
Also if your game have streaming enabled, those instances on the server you sent, might not be on the client, so it will return an error saying there is no such part in workspace
But If I do that the instances wont stay
Why are you sending the actual part to the client from the server? Just send a reference to the part instead.
Tried to see if it’s true that roblox does that, and happily found out it’s not. Printed the table on the server and client here. Then printed the values type. Can say they still remain numbers and don’t get converted to strings
Its the KEys not the values, if you set a instance as a key
--Server Script
local Table = {}
Table[workspace.Baseplate] = true
game.ReplicatedStorage.RemoteEvent:FireAllClients(Table)
--Local Script
wait(1)
game.ReplicatedStorage.RemoteEvent.OnClientEvent:Connect(function(Table)
print(Table)
end)
Remote events/functions can’t pass instances as a parameter. So that’s why you need to reference the part on the client. Let the server create the part, then send the reference of the part to the client.
what if parts have the same name
Could always put a value in the part to differentiate what they are
Once you send any userdata via RemoteEvent, you cannot reference them directly (but you can still iterate over them).
Non-String Indices
If any indices of a passed table are non-string type (
Instance
, userdata, function, another table, etc.), those indices will be converted to a string.
Your friend is right. Come up with a different way to send your data.