i dont get these, i get the functionality but the dev documentary cinfuses me like i understand i can do st = sharedtable.new({}) but how do i insert stuff, i cant do table.insert right? in the documentary it just gives example with already set values my question is how to insert new values
If you’re talking about adding new values you can just set it through
st[#st + 1] = myValue -- Gets length of st and adds 1 to not overwrite the value
I’m pretty sure table.insert would work fine as well
1 Like
This wouldn’t work as it will throw attempt to get length of a SharedTable value error.
You can however use update, or just setting a random key.
local st = SharedTable.new({})
-- add a new value to the table.
-- or insert in your case.
st["key"] = 1
-- update the key.
-- v argument is the value.
SharedTable.update(st, "key", function(v) return v + 1 end)
print(st) -- ["key"] = 2
You can also use SharedTable | Documentation - Roblox Creator Hub
2 Likes