For some reason my for loop isn’t doing anything. It runs (I tested with print statements) and the player variable inside the list is correct. So not sure why its not working?? I get no error messages in output.
-- Stopping players from being able to move
for i = team1Num, 1, -1 do
team1[i].Character.Humanoid.WalkSpeed = 0
team2[i].Character.Humanoid.WalkSpeed = 0
end
Function that gets the player that touches a part (I have a few of these for different parts)
T1P1.Touched:Connect(function(touchedPart) -- TOUCHED PART IS THE PART OF THE CHARACTER THAT TOUCHES THE PART, SO BY GETTING ITS PARENT, I'M GETTING THE PLAYERS CHARACTER
local Player = Players:GetPlayerFromCharacter(touchedPart.Parent) -- FUNCTION TO GET THE PLAYER FROM CHARACTER
if T1Player1 == nil then
T1Player1 = Player
T1Player1Prev = Player
T1B1.BrickColor = BrickColor.new("Teal")
T1P1.Transparency = 0.75
T1P2.Base.Transparency = 0
checkReady()
end
end)
– This is where i add the player variables into the list:
if T1Player1 and T1Player2 and T1Player3 and T2Player1 and T2Player2 and T2Player3 then
gamePlayers = {T1Player1, T1Player2, T1Player3, T2Player1, T2Player2, T2Player3}
for i = 6, 1, -1 do
gamePlayers[i].PlayerGui.ScreenGui.Enabled = true
end
team1 = {T1Player1, T1Player2, T1Player3}
team2 = {T2Player1, T2Player2, T2Player3}
numPlayers = 6
elseif T1Player1 and T1Player2 and T2Player1 and T2Player2 and T1Player3 == nil and T2Player3 == nil then
gamePlayers = {T1Player1, T1Player2, T2Player1, T2Player2}
for i = 4, 1, -1 do
gamePlayers[i].PlayerGui.ScreenGui.Enabled = true
end
team1 = {T1Player1, T1Player2}
team2 = {T2Player1, T2Player2}
numPlayers = 4
elseif T1Player1 and T2Player1 and T1Player2 == nil and T1Player3 == nil and T2Player2 == nil and T2Player3 == nil then
gamePlayers = {T1Player1, T2Player1}
for i = 2, 1, -1 do
gamePlayers[i].PlayerGui.ScreenGui.Enabled = true
end
team1 = {T1Player1}
team2 = {T2Player1}
numPlayers = 2
I have code right after the setting walkspeed part that uses the variables inside the lists and those all work perfectly
for i = team1Num, 1, -1 do
team1[i].Character.Humanoid.WalkSpeed = 0
team2[i].Character.Humanoid.WalkSpeed = 0
end
-- Setting the players teams so they can't kill their teammates
for i = team1Num, 1, -1 do
team1[i].Team = Teams["Team1"]
end
for i = team2Num, 1, -1 do
team2[i].Team = Teams["Team2"]
end
-- Teleporting players into the arena
for i = team1Num, 1, -1 do
if team1Num == 1 or team1Num == 3 then
workspace[team1[i].Name].HumanoidRootPart.CFrame = team1Teleports[i].CFrame
elseif team1Num == 2 then
workspace[team1[i].Name].HumanoidRootPart.CFrame = team1Teleports[i+1].CFrame
end
end
for i = team2Num, 1, -1 do
if team2Num == 1 or team2Num == 3 then
workspace[team2[i].Name].HumanoidRootPart.CFrame = team2Teleports[i].CFrame
elseif team1Num == 2 then
workspace[team2[i].Name].HumanoidRootPart.CFrame = team2Teleports[i+1].CFrame
end
end
Like the players are assigned to the teams fine and they are teleported fine.
-- Stopping players from being able to move
for i = team1Num, 1, -1 do
team1[i].Character.Humanoid.WalkSpeed = 0
team2[i].Character.Humanoid.WalkSpeed = 0
print(team2[i].Character.Humanoid.WalkSpeed)
print(team1[i].Character.Humanoid.WalkSpeed)
end
I’ve just had an idea. I have a countdown gui, but that isn’t showing up either… If that for loop wasn’t working there would be basically no time gap between the speed getting set to 0 and back to 16.
for i = numPlayers, 1, -1 do
gamePlayers[i].PlayerGui.Countdown.Enabled = true
end
for i = 3, 1 -1 do
if numPlayers == 6 then
gamePlayers[1].PlayerGui.Countdown.Frame.TextLabel.Text = i
gamePlayers[2].PlayerGui.Countdown.Frame.TextLabel.Text = i
gamePlayers[3].PlayerGui.Countdown.Frame.TextLabel.Text = i
gamePlayers[4].PlayerGui.Countdown.Frame.TextLabel.Text = i
gamePlayers[5].PlayerGui.Countdown.Frame.TextLabel.Text = i
gamePlayers[6].PlayerGui.Countdown.Frame.TextLabel.Text = i
elseif numPlayers == 4 then
gamePlayers[1].PlayerGui.Countdown.Frame.TextLabel.Text = i
gamePlayers[2].PlayerGui.Countdown.Frame.TextLabel.Text = i
gamePlayers[3].PlayerGui.Countdown.Frame.TextLabel.Text = i
gamePlayers[4].PlayerGui.Countdown.Frame.TextLabel.Text = i
elseif numPlayers == 2 then
gamePlayers[1].PlayerGui.Countdown.Frame.TextLabel.Text = i
gamePlayers[2].PlayerGui.Countdown.Frame.TextLabel.Text = i
end
task.wait(1)
end
for i = numPlayers, 1, -1 do
gamePlayers[i].PlayerGui.Countdown.Enabled = false
end
-- Resetting all the players walkspeed
for i = #gamePlayers, 1, -1 do
gamePlayers[i].Character.Humanoid.WalkSpeed = 16
end