I made a basic round system and there is a part where it loads the map and after it does that it teleports you to the map. As soon as it got to line 42 of the code it gave me an error which was 'ServerScriptService.CS_ServerScriptService.CS_GameComponents.GameManager:42: bad argument #1 to 'new' (Vector3 expected, got nil)'.
Then I switched CFrame to Vector3 and I got this error on line 44 'ServerScriptService.CS_ServerScriptService.CS_GameComponents.GameManager:44: bad argument #3 to 'CFrame' (CFrame expected, got Vector3)', so then I switched it to CFrame instead of Vector3.
Suddenly, I got another error saying 'ServerScriptService.CS_ServerScriptService.CS_GameComponents.GameManager:44: bad argument #2 to '?' (Vector3 expected, got CFrame)'. It told me to change Vector3 to CFrame before, but now it want's me to change CFrame to Vector3.
I was wondering if anyone could help me find a solution to this mess, thanks!
Teleportation Code:
function teleportAllPlayers() local mapSpawn = CFrame.new(mapClone.Spawns:GetChildren().Position) for i, player in ipairs(game.Players:GetChildren()) do player.Character.Torso.CFrame = mapSpawn + Vector3.new(0, i * 5, 0) player.Playing.Value = 1 end end
Round Script:
function playerNotification(changeText) for _,v in pairs (game.Players:GetChildren()) do local gameInterface = v.PlayerGui:FindFirstChild("GameInterface") if gameInterface then gameInterface.Frame.TextLabel.Text = changeText end end end function waitForPlayers() while game.Players.NumPlayers < 2 do playerNotification("You need 1 more player to start the round!") wait(0) end end function intermissionTimer() if game.Players.NumPlayers >= 2 then for countDown = 10, 0, -1 do playerNotification("Intermission: " ..countDown) wait(1) end end end function displayGamemode() end function mapSelection() mapList = game.ReplicatedStorage.CS_ReplicatedStorage.CS_Maps.Maps:GetChildren() randomMap = math.random(1, #mapList) playerNotification("Choosing the map!") wait(4) mapChosen = mapList[randomMap] playerNotification("The map is: " ..mapChosen.Name) mapClone = mapChosen:Clone() mapClone.Parent = game.Workspace end function teleportAllPlayers() local mapSpawn = CFrame.new(mapClone.Spawns:GetChildren().Position) for i, player in ipairs(game.Players:GetChildren()) do player.Character.Torso.CFrame = mapSpawn + Vector3.new(0, i * 5, 0) player.Playing.Value = 1 end end function startTimer() for countDown = 3, 0, -1 do playerNotification("Game begins in: " ..countDown) wait(1) end end function roundTimer() for countDown = 20, 0, -1 do playerNotification("Time left: " ..countDown) wait(1) end end function playersCurrentlyPlaying() for i, player in ipairs(game.Players:GetChildren()) do if player.Playing.Value == 1 then return true end end return false end function roundEnded() playerNotification("The round has ended!") end function teleportAlivePlayers() local mapSpawn = CFrame.new(workspace.CS_Workspace.CS_Lobby.Lobby.Spawns:GetChildren().Position) for i, player in ipairs(game.Players:GetChildren()) do player.Character.Torso.CFrame = mapSpawn + Vector3.new(0, i * 5, 0) player.Playing.Value = 0 end end function mapDestroy() if mapClone.Parent == game.Workspace then mapClone:Destroy() end end function showResults() end game:GetService('Players').PlayerAdded:connect(function(Player) Player.CharacterAdded:connect(function(Character) Character:FindFirstChild("Humanoid").Died:connect(function() Player.Playing.Value = 0 end) end) local Playing = Instance.new("IntValue", Player) Playing.Value = 0 Playing.Name = "Playing" end) while true do waitForPlayers() wait(0) intermissionTimer() wait(0) displayGamemode() wait(5) mapSelection() wait(5) teleportAllPlayers() wait(0) startTimer() wait(0) roundTimer() wait(0) playersCurrentlyPlaying() wait(0) roundEnded() wait(0) teleportAlivePlayers() wait(0) mapDestroy() wait(0) showResults() end
mapClone.Spawns:GetChildren().Position
does not make sense. GetChildren
returns a table.
It looks like you're trying to teleport players to a random spawn inside of mapClone.Spawns
.
TeleportAllPlayers
and TeleportAlivePlayers
should look like this:
function teleportAllPlayers() local spawns = mapClone.Spawns:GetChildren() for i, player in ipairs(game.Players:GetChildren()) do player.Character.Torso.CFrame = spawns[math.random(#spawns)].CFrame + Vector3.new(0, i * 5, 0) player.Playing.Value = 1 end end function teleportAlivePlayers() local spawns = workspace.CS_Workspace.CS_Lobby.Lobby.Spawns:GetChildren() for i, player in ipairs(game.Players:GetChildren()) do player.Character.Torso.CFrame = spawns[math.random(#spawns)].CFrame + Vector3.new(0, i * 5, 0) player.Playing.Value = 0 end end