Acessing a table, both locally and serverside

So I’m creating a radio system, in which the previous 12 transmissions are stored in a Table. However, when a new user loads into the Radio, I’m not sure how to acess the transmissions to load them? I was gonna have the Table Server Side, and have a Local Script access it, but that doesnt work because Module scripts suck.

Anyway, is there an efficient way to do it, without a loop, since the game struggles from lag already.

My initial way, was to have an Int value changed by the Server, which would trigger a GetPropertyChangedSignal, but thats not working, nor is it the most secure.

I would recommend you make use of either a RemoteEvent or a RemoteFunction.

Using these allows you to communicate between the server and the client, and you should be able to transfer the table with the 12 transmissions using it.

I’m not completely sure if this covers your issue, however you could potentially do this

Server Side

local last12Transmissions = {}  

local getTable =  game.ReplicatedStorage:WaitForChild("RemoteFunction") 


-- Return the transmissions table to the client
getTable.OnServerInvoke = function(player)
    return last12Transmissions
end

-- Store the transmissions in the server side
function addTransmission(transmission)
    table.insert(last12Transmissions, 1, transmission)  -- Insert the new transmission in the beggining
    if #last12Transmissions > 12 then
        table.remove(last12Transmissions)  -- Remove the oldest transmission
    end
end

Client

local getTable = game.ReplicatedStorage:WaitForChild("RemoteFunction")

-- Request the transmissions table from the server
local last12Transmissions = getTable:InvokeServer()

Explanation

table.remove(table, x) – Removes an element from a table at the specified position x, if x is not defined it will remove the last element in the table

rest should be pretty self explanatory

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.