Hello NinjoOnline,
I’ve stumbled across the same problem, however I somehow found a work-around solution in case you or other developers come across the same problem.
Please note that this only works with Arrays
API’s used: table.find(TableName, Text) & table.remove(TableName, Text)
https://developer.roblox.com/en-us/api-reference/lua-docs/table
https://developer.roblox.com/en-us/articles/Table
Example:
When a player joins, you insert their UserId. When they leave, you remove it.
TEMPLATE
--[[
1.
DEFINING THE SERVICE(S) REQUIRED (similar to import os in python, in case you learn better by connecting prior knowladge.
]]--
local PlayerService = game:GetService("Players")
--[[
2.
Creating a table
--]]
local DataOnTheServer = {} --[[ AN EMPTY TABLE IS CREATED ]]--
--[[
3.
Using PlayerAdded/PlayerRemoving to detect/remove player data in the table.
]]--
PlayerService.PlayerAdded:Connect(function(Player)
table.insert(DataOnTheServer, Player.UserId)
end)
PlayerService.PlayerRemoving:Connect(function(Player)
table.remove(DataOnTheServer, table.find(DataOnTheServer, Player.UserId))
end)
To sum it up:
SOLUTION
table.remove(NameOfTable, table.find(NameOfTable, Value))
Still don’t understand it?
-
Wishing to remove data? Yes, me too.
-
Use table.remove(NameOfTable, Value) but Lua will not recognize the value Player.UserId, therefore WE USE table.find(NameOfTable, Value) to define the value.
You can further customize this to your liking, I’ve been tying this to datastore requests, say 10 seconds into a game, the client automatically requests it via a local script tied to a remote event.
(to make sure the player can not abuse PlayerService.PlayerAdded and PlayerRemoving)
To avoid the client to abuse the remote event (exploiters with their executors sending requests to the server by remote events), I insert their data into the table & properties like checking script validity (pass the script in the remote event, real handy), checking if they had requested it in the past, if so it would kick them.
This can easily be bypassed by calling the remote events on join via an exploiters ‘executor’, I’m working on a workaround on that.
This is just an example, get creative!
I am in no way a professional, this is a hobby. If you find solutions that help performance, do not hesitate to edit it further (: