I have a remote function to get the length of a list which is stored on the server, but I cannot seem to get the remote function to send the correct length of the list when it is updated. I just constantly get 0. I am thinking its something to do with the listLen variable within the function, but I am not sure how to resolve it.
PlrsList = {}
game.ReplicatedStorage.RemoveRecentPlr.OnServerEvent:Connect(function(plr)
print("BEFORE REMOVE")
table.remove(PlrsList, 1)
table.insert(PlrsList, plr.Name)
print("AFTER REMOVE")
end)
game.ReplicatedStorage.AddRecentPlr.OnServerEvent:Connect(function(plr)
print("ADDING PLAYER NAME!")
table.insert(PlrsList, plr.Name)
end)
game.ReplicatedStorage.ReturnListLen.OnServerInvoke = function(plr)
local listLen = #PlrsList
return listLen
end
Hi, so the first event shouldn’t be inserting, I forgot to remove that. But when a button is pressed on the client, the remote function is called to check the length of the list. If the list is a certain length, the first event is fired to remove the first element, and then the second event is later called to append the name of the player who pressed the button.
The print statements are working correctly, and when I check the list length within the remote events, I get the correct output. It’s only when I try to get the list length through the remote function that I always get 0.
I decided to ditch the remote function and tried firing the client with a remote event to send the list length instead which seems to be working perfectly now.