Hello, I am trying to get the name of the player that clicked on a textlabel that is in a surface gui. This is just for some tic tac toe game that i’m making. This code would just prevent the other player from playing the turn for the opponent.
Heres my script:
for i, square in pairs(squares:GetChildren()) do
square.MouseButton1Click:Connect(function(plr)
if plr.Name == playeruserturn then
if turn == "x" then
elseif turn == "o" then
end
end
end)
end
This was written in a regular script in workspace, not a local script.
“square” is referring to the textlabel.
for i, square in pairs(squares:GetChildren()) do
square.MouseButton1Click:Connect(function(plr)
if game.Players.LocalPlayer.Name == "USERNAME" then
if turn == "x" then
elseif turn == "o" then
end
end
end)
end
If you’re using a localscript (which I hope you are) this should work
The script must be a local script so you can change the gui and also use the MouseButton1Click event. You can send a remote event to the server from this local script, then a remote event to the another client from the server script (the server must act as a “middle man” for remote events between clients).