Down there it's the full code, but on that big gap, is where I think I'm mistaking somewhere.
So basically, there's GUI For both players, and the TextValue for the GUI is based on theText but somehow the first player that joins the table, the value is +1 than the other one, anyone knows why?
local RoomOnePlayers = require(game.ReplicatedStorage.RoomsTable.RoomOne)
local PartToClick = workspace.clickToJoinParts.RoomOne
workspace.clickToJoinParts.RoomOne.ClickDetector.MouseClick:Connect(function(click)
if #RoomOnePlayers >= 2 then
print("Room is full")
else
if table.find(RoomOnePlayers, click) then
print("You are already in the table")
else
--insert table
table.insert(RoomOnePlayers, click)
if RoomOnePlayers[1] then
RoomOnePlayers[1].Character.HumanoidRootPart.CFrame = CFrame.new(-287.1, 68.125, -63.95)
PartToClick.BrickColor = BrickColor.new("Neon orange")
end
RoomOnePlayers[1].PlayerGui.RoomOne.mainText.TextLabel.Text = "Waiting for another player..."
if RoomOnePlayers[2] then
RoomOnePlayers[2].Character.HumanoidRootPart.CFrame = CFrame.new(-284.46, 68.69, -27.42)
PartToClick.BrickColor = BrickColor.new("Really red")
end
if #RoomOnePlayers == 2 then
for i, v in pairs(RoomOnePlayers) do
local Points = Instance.new("IntValue")
Points.Name = "Points"
Points.Parent = v
end
-- game starting
local theText = workspace.GameCubes.RoomOne.actText
local t = 8
repeat
theText.Value = "Game starting in: "..t
t = t - 1
wait(1)
until t == 0
--revealing key
t = 5
repeat
theText.Value = "Revealing Key in: "..t
t = t-1
wait(1)
until RoomOnePlayers[1].Points.Value == 5 or RoomOnePlayers[2].Points.Value == 5
--Player 1 won game
if RoomOnePlayers[1].Points.Value == 5 then
theText.Value = "Player: "..RoomOnePlayers[1].Name.." Won The Game!"
end
--Player 2 won game
if RoomOnePlayers[2].Points.Value == 5 then
theText.Value = "Player: "..RoomOnePlayers[2].Name.." Won The Game!"
end
for i, v in pairs(RoomOnePlayers) do
v.Points:Destroy()
table.remove(RoomOnePlayers, i)
end
end
end
end
end)
