Challenge1.Event:Connect(function()
local AllPlayers = #Players:GetPlayers()
local HalfPlayers = math.round(AllPlayers * 0.5)
local RightSidePos = Vector3.new(RightSide.Position)
local LeftSidePos = Vector3.new(LeftSide.Position)
RaiseWall1:Fire()
wait(5)
for i, v in pairs(Players:GetPlayers()) do
v.Character:FindFirstChild("HumanoidRootPart").CFrame = CFrame.new(RightSidePos)
end
wait()
for i, v in pairs(HalfPlayers) do -- Error here, It's expecting something else, not a number
v.Character:FindFirstChild("HumanoidRootPart").CFrame = CFrame.new(LeftSidePos)
end
end)
When I call HalfPlayers in the for loop, it always seems to error.
Instead if you want half the players left over loop through them like so, first we get all the players
local PlayersLeft = Players:GetPlayers()
Now we will remove 50%.
-- i stands for how many times you remove players from the array
for i = 1,math.round(#PlayersLeft*.5) do
-- remove a random value from the table.
table.remove(PlayersLeft, math.random(#PlayersLeft))
end
local Players = game:GetService("Players"):GetPlayers()
local HalfPlayers = {}
for i = 1,#Players / 2 do
if #Players == 0 or 1 then return end
table.insert(HalfPlayers, Players[math.random(#Players)])
end
for i, v in (HalfPlayers) do
v.Character:FindFirstChild("HumanoidRootPart").CFrame = CFrame.new(LeftSidePos)
end