I'm working on my first large Roblox script that links two players into a team for an obby-style game. Each link station has two buttons. When a player steps on one, they are frozen in place (including animations), rotated to face a certain direction, and a UI appears saying “Waiting for players...” with an “Exit” button. Clicking “Exit” unfreezes them and moves them a few studs away.
When two players are on paired buttons, a 3-second countdown begins. If neither player cancels, they’re teleported to separate spawn points and placed on a shared team named after one of them.
The problem: I had a bug where one player's UI didn’t disappear after linking. To fix it, I added a remote event to disable the UI for both players once they’re linked. But once I added this, the onBothPlayersReady() function fails because the variables playerA and playerB become nil unexpectedly. The function has a safety check that exits early if either is missing, so linking never happens.
I deleted the new remote event and related code, but the issue still persists. I’ve spent hours debugging and confirmed it’s not due to canceling, death, or character respawning. Here are the two scripts involved.
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Remotes = ReplicatedStorage:WaitForChild("Remotes")
local StartLinkCountdown = Remotes:WaitForChild("StartLinkCountdown")
local CancelLink = Remotes:WaitForChild("CancelLink")
local UpdateLinkStatus = Remotes:WaitForChild("UpdateLinkStatus")
local ShowWaitingStatus = Remotes:WaitForChild("ShowWaitingStatus")
local LinkConfirmed = Remotes:WaitForChild("LinkConfirmed")
local LinkFailed = Remotes:WaitForChild("LinkFailed")
local player = Players.LocalPlayer
local ui = script.Parent
local cancelButton = ui:WaitForChild("CancelButton")
local cancelPress = ui:WaitForChild("CancelPressButton")
local countDownTask = nil
local currentStation = nil
local currentSide = nil
cancelButton.MouseButton1Click:Connect(function()
ui.Enabled = false
if countDownTask then
task.cancel(countDownTask)
end
CancelLink:FireServer(currentSide, currentStation)
end)
StartLinkCountdown.OnClientEvent:Connect(function(side, stationName)
currentStation = stationName
currentSide = side
ui.Enabled = true
cancelButton.Visible = true
cancelPress.Visible = true
local countdown = 3
countDownTask = task.spawn(function()
while countdown > 0 do
cancelPress.Text = "Linking in " .. countdown .. "..."
countdown -= 1
task.wait(1)
end
if countdown <= 0 then
ui.Enabled = false
LinkConfirmed:FireServer(currentSide, currentStation)
end
end)
end)
UpdateLinkStatus.OnClientEvent:Connect(function(message)
ui.Enabled = true
cancelButton.Visible = true
cancelPress.Visible = true
cancelPress.Text = message
end)
ShowWaitingStatus.OnClientEvent:Connect(function(side, stationName)
currentStation = stationName
currentSide = side
ui.Enabled = true
cancelButton.Visible = true
cancelPress.Visible = true
cancelPress.Text = "Waiting for players..."
end)
LinkFailed.OnClientEvent:Connect(function()
ui.Enabled = true
cancelButton.Visible = true
cancelPress.Visible = true
cancelPress.Text = "Waiting for players..."
end)```
Apologies in advance for likely the poorly written code.
** You are now Level 2! **