Remote function not updating variable to return

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

I don’t understand what your two remote events do?
One just replaces the first element of the list with a new player, and the other adds a player.

Could you provide more details on what you’re trying to do and if the remotes get called or not? (print statements printed?)

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.

Why not just use a ModuleScript and game.Players.PlayerAdded, it would make what you’re doing here much easier.

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.

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