local Players = game:GetService("Players")
local SpawnLocations = workspace.SpawnLocations
local requiredPlayers = 15
local i = 1
Players.CharacterAutoLoads = false
Players.PlayerAdded:Connect(function(Player)
Player.RespawnLocation = SpawnLocations[i] -- Assign new Player to a Spawn
i = i + 1
Player:LoadCharacter()
end)
local event = game.ReplicatedStorage.RemoteEvent
event.Name = "playercountGUI"
event.Parent = game.Workspace
while i ~= requiredPlayers do
event.OnServerEvent:connect(function()
end)
end
while i ~= requiredPlayers do
local screenGui = Instance.new("ScreenGui")
screenGui.Parent = script.Parent
local textLabel = Instance.new("TextLabel")
textLabel.Parent = screenGui
textLabel.Position = UDim2.new(0, 495, 0, 25)
textLabel.Size = UDim2.new(0, 150, 0, 50)
textLabel.BackgroundColor3 = BrickColor.Black().Color
textLabel.BackgroundTransparency = 0.5
textLabel.Font = Enum.Font.ArialBold
textLabel.Fontsize = Enum.FontSize.Size18
textLabel.Text = "Players: " .. i
textLabel.TextColor3 = BrickColor.White().Color
end
The first part of code defines the event, while the second part of the code is the event I have coded.
My issue is I have absolutely NO IDEA how to transfer the variable i between the event and the code.
Please help. (This is also my first time creating a RemoteEvent.)

6 comments
Is this the entirety of the code, on both clientside and server-side?
iis never defined, here.No, but I can post everything.
Posted the whole code
At no point during this code are you firing the event. You have created it but you're not activating it.
I'm unsure how to activate it.
I may be a little late, but to fire the event to the server, use :FireServer() on the LocalScript