Player List not working?

I am trying to make a player list for a tip jar, but my remote event isn’t working, could someone tell me what I did wrong?

Script 1

players.PlayerAdded:Connect(function(player)
	event:FireClient(player, "Add")
end)

Local Script 2

event.OnClientEvent:Connect(function(player, request)
	if request == "Add" then
		if not list:FindFirstChild(player.Name) then
			local templateClone = template:Clone()
			templateClone.Visible = true
			templateClone.Parent = list
		end
	end
end)
1 Like

You fire it when they just join, but local scripts may not have loaded yet and been replicated. Consider waiting a couple seconds for the player to load, or fire it when the character spawns using .CharacterAdded:Wait().

1 Like
players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function()
		event:FireClient(player, "Add")
	end)
end)

Like this?

The server script is loaded first, before the player’s UI is loaded. I’m assuming the local script is in PlayerUI, so the event is fired before the event listener is registered.

My suggestion is that you add a :WaitForChild for the local script, or for the UI.

It could look like this.

players.PlayerAdded:Connect(function(player)
        player.PlayerGui:WaitForChild("PathToLocalScript") -- Possibly PathToUI
	event:FireClient(player, "Add")
end)

Hope I could help!

Nope, didn’t work. I don’t think its something with waiting for the script to load.

Sorry I didnt see this sooner, the issue is that player is not a variable for OnClientEvent. So request is undefined, and player is “Add”.

You need to remove the “player” variable from the event.

event.OnClientEvent:Connect(function(request)

Hopefully this works.

(Referenced the RemoteEvent Documentation)

Yes, try it out. You can’t just run server code involving the client before it’s loaded completely.

After that, add some print statements and make sure it’s running properly.

Thanks, I completely forgot about that!

Just as a note, there should have been an undefined error in the F9 menu. You can check that out next time if you need a faster solution.

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