Ok. So I want to make a fighting arena where 2 players can click a button and be assigned player one or player two. To get who clicked the button I used this local script:
wait(.1) --Wait for player to load in
player = game.Players.LocalPlayer --Get the local player
_G.player1 = nil --Declare player1 global variable
_G.player2 = nil --Declare player2 global variable
script.Parent.TextButton.MouseButton1Click:connect(function() --Runs function if player clicks the button
if _G.player1 == nil then --Make sure player1 has not been chosen yet
_G.player1 = player --If it hasnt been chosen, assign local player to player1
elseif _G.player1 ~= player then --Makes sure the same player has not clicked it twice
_G.player2 = player --If it hasnt been chosen, assign local player to player2
game.Workspace.PlayerChosen:FireServer() --Fire the spawn event in my normal script that you will see later
end
end)
My normal script:
local event = Instance.new("RemoteEvent") --makes the spawn event
event.Name = "PlayerChosen" --Names the event
event.Parent = game.Workspace --placing the event in workspace
event.OnServerEvent:connect(function() --runs when event is called in local script
print("Spawning " .. _G.player1 .. " and " .. _G.player2 .. ". Good luck!") --Just used to see if the event did run
_G.player1 = nil --sets player1 and 2 back to nil so they can be chosen again
_G.player2 = nil
end)
So you are probably asking what the problem is. Well when I click the button, nothing happens. The button is set up as a text button and is adorneed to a brick. No errors. No output that is in the normal script. No nothing.

1 comment
Don't use _G.