Guess who found the solution!
Turns out due to the
local PickablePlayers = {game.Players:GetPlayers()}
line RandomPlayer1 and 2 where being set to table values. The :GetPlayers() function already returns a table so no need to add extra brackets around em! no clue why my pea brain didnt spot this. Here is the working code
local Players = game.Players:GetPlayers()
local CountValue = Instance.new("IntValue")
CountValue.Parent = workspace
for i, Count in pairs(Players) do
CountValue.Value = i
end
if CountValue.Value > 1 then
print("2playersingame")
local PickablePlayers = game.Players:GetPlayers()
local RandomPlayer1 = PickablePlayers[math.random(1,#PickablePlayers)]
local RandomPlayer2 = PickablePlayers[math.random(1,#PickablePlayers)]
if RandomPlayer1 == RandomPlayer2 then
print("Oops")
repeat
RandomPlayer2 = PickablePlayers[math.random(1,#PickablePlayers)]
task.wait(.2)
print(RandomPlayer1,RandomPlayer2)
until RandomPlayer1 ~= RandomPlayer2
end
local P1Char = RandomPlayer1.Character:GetChildren()
local P2Char = RandomPlayer2.Character:GetChildren()
print(RandomPlayer1.Name,RandomPlayer2.Name)
if P1Char and P2Char then
print("Running code")
for i, Part in pairs(P1Char) do
if Part:IsA("BasePart") then
Part.Transparency = 1
end
if Part:IsA("Accessory") then
Part:Destroy()
end
end
for i, Part in pairs(P2Char) do
if Part:IsA("BasePart") then
Part.Transparency = 1
end
if Part:IsA("Accessory") then
Part:Destroy()
end
end
task.wait(3)
for _, Part in pairs(P1Char) do
if Part:IsA("BasePart") then
Part.Transparency = 0
end
if Part.Name == "HumanoidRootPart" then
Part.Transparency = 1
end
end
for _, Part in pairs(P2Char) do
if Part:IsA("BasePart") then
Part.Transparency = 0
end
if Part.Name == "HumanoidRootPart" then
Part.Transparency = 1
end
end
end
end