When I fire the server it prints my username

Hello, I am trying to make it so you can make your private server have a certain amount of players in it, for example you type in 5 and only 5 people can join now. Whenever you type it in it sends to a local script from the text box which is read by a server script after being fired, then it sets _G.maxPlayers to your variable, but it sets it to my name when printing.

Code:

--Local Script
local button = script.Parent
local RemoteEvent = game:GetService("ReplicatedStorage").maxPlayers
local TextBox = script.Parent.Parent.TextBox
button.MouseButton1Click:Connect(function()
	
	print(script.Parent.Parent.TextBox.Text)
	
	RemoteEvent:FireServer(tonumber(script.Parent.Parent.TextBox.Text))

end)

local function maxPlayersFunction(maxPlayersValue)
	print(maxPlayersValue)
	
	_G.maxPlayers = maxPlayersValue
end

RemoteEvent.OnServerEvent:Connect(maxPlayersFunction)

Iā€™m not good with code, so if anyone can help that would be great!

When a client fires a remote event to the server, the first argument is the player, which is why it prints the players name instead of what you want it to.

remoteEvent.OnServerEvent:Connect(function(Player, [your stuff here])
1 Like

Ah, makes sense now that I think about it. Thanks!

I should also mention, that you dont have to send the player argument from the client to the server.
So the client would just stay how youve scripted it, and for the server, just put the Player argument before your value in the function

1 Like