Can't register when another player clicks [SOLVED]

Hello. I am trying to make tic tac toe and of course it needs two players. But I have this problem where I can’t detect when another player is trying to join the game.

local count = script.Parent.Count
local player = script.Parent.Player
local clicked = false

script.Parent.MouseClick:Connect(function(plr)	
	if clicked == false and count.Value == 0 or nil then
		clicked = true
		count.Value = count.Value + 1
		game.Players[plr.Name].PlayerGui.TicTacToe.Waiting.Visible = true
		player.Value = plr.Name
	elseif count.Value == 1 and clicked == false and player.Value ~= plr.Name then
		clicked = true
		count.Value = count.Value + 1
		game.Players[plr.Name].PlayerGui.TicTacToe.Frame.Status.Text = "You're against: "..player.Value
		game.Players[player.Value].PlayerGui.TicTacToe.Frame.Status.Text = "You're against: "..plr.Name
		game.Players[plr.Name].PlayerGui.TicTacToe.Frame.Visible = true
		game.Players[player.Value].PlayerGui.TicTacToe.Frame.Visible = true
		wait(3)
	end
end)

game:GetService("ReplicatedStorage"):WaitForChild("TicTacToe").OnServerEvent:Connect(function(playerr)
	if clicked == true then
		clicked = false
		count.Value = 0
		game.Players[playerr.Name].PlayerGui.TicTacToe.Waiting.Visible = false
		player.Value = ""
	end
end)

image

3 Likes

I solved it by making a ‘Clicked’ BoolValue in each players PlayerGui to check if they have clicked. I did that because the script is the same for each player so it wouldn’t work just to make a variable in the script I needed something for each player.

1 Like