Round System Not Teleporting Properly

My round system is only teleporting 1 player.

This is the Action Script
–Classic
script.Parent.Changed:Connect(function()
if script.Parent.Value == “Classic” then
game.Workspace.Map.Field.Shrinker.Disabled = false
for _, player in pairs(game.Players:GetPlayers()) do
player.Character:MoveTo(Vector3.new(math.random(0,100),30,math.random(0,100)))
if player.Stats.Weapon.Value == nil then
local pw = script.Parent.Main.GameModes.Classic:GetChildren()[math.random(1,#script.Parent.Main.GameModes.Classic:GetChildren())]
local pwc = pw:Clone()
pwc.Parent = player.Backpack
else
local bruh = player.Stats.Weapon.Value:Clone()
bruh.Parent = player.Backpack
end
end
repeat wait(.5) until game.Workspace.Map.Field.Size == Vector3.new(1,20,20)
script.Parent.Value = “Intermission”
end
end)

–Juggernaut
script.Parent.Changed:Connect(function()
if script.Parent.Value == “Juggernaut” then
game.Workspace.Map.Field.Shrinker.Disabled = false
local jugger = game.Players:GetChildren()[math.random(1,#game.Players:GetChildren())]
for _, player in pairs(game.Players:GetChildren()) do
if player == jugger then
player.Character:MoveTo(Vector3.new(0,30,0))
local wepin = script.Parent.Main.GameModes.Juggernaut.JHammer
local myw = wepin:Clone()
myw.Parent = player.Backpack
else
if player.Stats.Weapon.Value == nil then
local pw = script.Parent.Main.GameModes.Classic:GetChildren()[math.random(1,#script.Parent.Main.GameModes.Classic:GetChildren())]
local pwc = pw:Clone()
else
local bruh = player.Stats.Weapon.Value:Clone()
bruh.Parent = player.Backpack
end
end
end
repeat wait(.5) until game.Workspace.Map.Field.Size == Vector3.new(1,20,20)
script.Parent.Value = “Intermission”
end
end)

–Intermission
script.Parent.Changed:Connect(function()
if script.Parent.Value == “Intermission” then
game.Workspace.Map.Field.Shrinker.Disabled = true
game.Workspace.Map.Field.Size = Vector3.new(1,1000,1000)
for _, player in pairs(game.Players:GetPlayers()) do
player.Character:MoveTo(Vector3.new(math.random(0,25),175,math.random(0,25)))
player.Backpack:ClearAllChildren()
if player.Character:FindFirstChildWhichIsA(“Tool”) then
player.Character:FindFirstChildWhichIsA(“Tool”):Remove()
end
end
end
end)

This is the Main Script
wait(3)
script.Parent.Value = “Intermission”

while true do
wait(.3)
if script.Parent.Value == “Intermission” then
wait(7)
script.Parent.Value = “Choosing Gamemode…”
end
if script.Parent.Value == “Choosing Gamemode…” then
local gamemodechosen = script.GameModes:GetChildren()[math.random(1,#script.GameModes:GetChildren())]
script.Parent.Value = gamemodechosen.Name
end
end

A picture of my explorer is attatched.
image

1 Like

My suggestion to this is use the lua format when you are adding a code in the problem (So it doesn’t hard to read when we are reading your code).

Just like this:

local hello = "Hello World!"

function justNormalFunction()
    print(hello) -- Hello World!
end

How to do this?

  • Simply, add three “grave” characters (on the left side of number 1 key on a common keyboard).
  • Next, add “lua” next to it (No white-space/space)
  • Paste your code in the middle.
  • And finally to close the special format just add three more “grave” characters.
  • Full context:
    ```lua (The code here)```

If you do this, Some of Developers here might know your problem faster.

Thank you, I will keep that in mind in the future, but do you have a solution?

Here is your code formatted slightly better so we can read it easier:

–Classic
script.Parent.Changed:Connect(function()
if script.Parent.Value == “Classic” then
game.Workspace.Map.Field.Shrinker.Disabled = false
for _, player in pairs(game.Players:GetPlayers()) do
player.Character:MoveTo(Vector3.new(math.random(0,100),30,math.random(0,100)))
if player.Stats.Weapon.Value == nil then
local pw = script.Parent.Main.GameModes.Classic:GetChildren()[math.random(1,#script.Parent.Main.GameModes.Classic:GetChildren())]
local pwc = pw:Clone()
pwc.Parent = player.Backpack
else
local bruh = player.Stats.Weapon.Value:Clone()
bruh.Parent = player.Backpack
end
end
repeat wait(.5) until game.Workspace.Map.Field.Size == Vector3.new(1,20,20)
script.Parent.Value = “Intermission”
end
end)

–Juggernaut
script.Parent.Changed:Connect(function()
if script.Parent.Value == “Juggernaut” then
game.Workspace.Map.Field.Shrinker.Disabled = false
local jugger = game.Players:GetChildren()[math.random(1,#game.Players:GetChildren())]
for _, player in pairs(game.Players:GetChildren()) do
if player == jugger then
player.Character:MoveTo(Vector3.new(0,30,0))
local wepin = script.Parent.Main.GameModes.Juggernaut.JHammer
local myw = wepin:Clone()
myw.Parent = player.Backpack
else
if player.Stats.Weapon.Value == nil then
local pw = script.Parent.Main.GameModes.Classic:GetChildren()[math.random(1,#script.Parent.Main.GameModes.Classic:GetChildren())]
local pwc = pw:Clone()
else
local bruh = player.Stats.Weapon.Value:Clone()
bruh.Parent = player.Backpack
end
end
end
repeat wait(.5) until game.Workspace.Map.Field.Size == Vector3.new(1,20,20)
script.Parent.Value = “Intermission”
end
end)

–Intermission
script.Parent.Changed:Connect(function()
if script.Parent.Value == “Intermission” then
game.Workspace.Map.Field.Shrinker.Disabled = true
game.Workspace.Map.Field.Size = Vector3.new(1,1000,1000)
for _, player in pairs(game.Players:GetPlayers()) do
player.Character:MoveTo(Vector3.new(math.random(0,25),175,math.random(0,25)))
player.Backpack:ClearAllChildren()
if player.Character:FindFirstChildWhichIsA(“Tool”) then
player.Character:FindFirstChildWhichIsA(“Tool”):Remove()
end
end
end
end)

This is the Main Script
wait(3)
script.Parent.Value = “Intermission”

while true do
wait(.3)
if script.Parent.Value == “Intermission” then
wait(7)
script.Parent.Value = “Choosing Gamemode…”
end
if script.Parent.Value == “Choosing Gamemode…” then
local gamemodechosen = script.GameModes:GetChildren()[math.random(1,#script.GameModes:GetChildren())]
script.Parent.Value = gamemodechosen.Name
end
end

Would you mind editing your post and make it as lua format? Im finding it hard to read, sorry.

Edit: Nvm someone already did it.

Thank you for reformatting, but do you guys have any idea why my system is teleporting only one player?

Have you getting some errors or some sort of warnings?

Also, What is the value of the StatusBar when the problem happens?

When it switches to “Juggernaut” or “Classic” everyone is supposed to teleport to the field. Instead, only one players does.

Do you have spawns around the map?

Try using player.Character.HumanoidRootPart

But the problem is that only one player is teleporting. I think the problem has to do with for For _, in pairs loop.

Depending on how quickly you’re running it (I assume on the server), some player characters may not be loaded in completely, and the condition only satisfies for some. You should always check if player’s characters exists, to prevent errors, dependent on it, e.g MoveTo()

for _, player in pairs(game.Players:GetPlayers()) do
	if player.Character or player.CharacterAdded:Wait() then
		player.Character:MoveTo(Vector3.new(math.random(0,100),30,math.random(0,100)))
	end
end

Also, reading over you code, I see these lines for your “Juggernaut”

local jugger = game.Players:GetChildren()[math.random(1,#game.Players:GetChildren())] 
if player == jugger then

You’re picking 1 random player, and seeing if there is any player in the game who is the juggernaut. Hence it only teleports one player because only one player can be a juggernaut. You should also do your part on debugging, e.g adding in prints and examining any errors in the output :slight_smile:

This is my same thoughts also, because when I tried the script it outputs me an error that the script is looking for MoveTo which output a nil value. so, I tried using a FindFirstChild() to solve this and it works.

the script on the Active on the intermission line:

for _, player in pairs(game.Players:GetPlayers()) do
	player.Character:MoveTo(Vector3.new(math.random(0,25),175,math.random(0,25)))
		player.Backpack:ClearAllChildren()
		if player.Character:FindFirstChildWhichIsA("Tool") then
			player.Character:FindFirstChildWhichIsA("Tool"):Remove()
		end
	end
end

Now my edited:

for _, player in pairs(game.Players:GetPlayers()) do
	if player:FindFirstChild("Character") then 
		player.Character:MoveTo(Vector3.new(math.random(0,25),175,math.random(0,25)))
		player.Backpack:ClearAllChildren()
		if player.Character:FindFirstChildWhichIsA("Tool") then
			player.Character:FindFirstChildWhichIsA("Tool"):Remove()
		end
	end
end

Thank you, I will try all of these suggestions, and tell you if any of them work.

Also, the gamemode never ends to start a new intermission, but this is only in local server mode. When I press play it works, but not local server. Could this be the problem?

Never mind, I found out that the source of the problem is a script in ServerScriptService that was interfering with my scripts. Thanks for all the help!