Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I fix this issue with players not teleporting back to the lobby after a round ends?

Asked by 3 years ago
Edited 3 years ago

Hi, I wanted to know how to fix this script for my bomb survival game (Yes, I know it's a copy of Super Bomb Survival, I'm only doing this for practice and I won't be releasing it to the public) For some reason though, the player won't teleport back to the spawn area.I have tried using teams and loading the player using LoadCharacter() to put them back into the lobby, but for some reason it didn't work. (By the way, this only happens if a player survives a whole round, if they die, they still get sent back to the lobby.) Anyways, here's the script:

local Bomb = game.ServerStorage.Bomb
local Coin = game.ServerStorage.Coin
local intermission = 30
local gameTime = 60
local InRound = game.ReplicatedStorage.InRound

InRound.Changed:Connect(function()

    for _, players in pairs(game.Players:GetChildren()) do
        local char = players.Character
        local playingTeam = game:GetService("Teams")["Playing"]

        players.Team = playingTeam


        if InRound.Value == true then

            local MapSpawnsFolder = game.Workspace.MapSpawns

            local MapSpawn1 = MapSpawnsFolder.MapSpawn1
            local MapSpawn2 = MapSpawnsFolder.MapSpawn2
            local MapSpawn3 = MapSpawnsFolder.MapSpawn3
            local MapSpawn4 = MapSpawnsFolder.MapSpawn4
            local MapSpawn5 = MapSpawnsFolder.MapSpawn5
            local MapSpawn6 = MapSpawnsFolder.MapSpawn6
            local MapSpawn7 = MapSpawnsFolder.MapSpawn7
            local MapSpawn8 = MapSpawnsFolder.MapSpawn8

            local spawnPicker = math.random(1, 8)


            -- pick a spawn on the MAP to send the player to
            if spawnPicker == 1 then
                local MapSpawnsFolder = game.Workspace.MapSpawns

                local MapSpawn1 = MapSpawnsFolder.MapSpawn1
                local MapSpawn2 = MapSpawnsFolder.MapSpawn2
                local MapSpawn3 = MapSpawnsFolder.MapSpawn3
                local MapSpawn4 = MapSpawnsFolder.MapSpawn4
                local MapSpawn5 = MapSpawnsFolder.MapSpawn5
                local MapSpawn6 = MapSpawnsFolder.MapSpawn6
                local MapSpawn7 = MapSpawnsFolder.MapSpawn7
                local MapSpawn8 = MapSpawnsFolder.MapSpawn8

                char.HumanoidRootPart.CFrame = MapSpawn1.CFrame

            elseif spawnPicker == 2 then
                char.HumanoidRootPart.CFrame = MapSpawn2.CFrame

            elseif spawnPicker == 3 then
                char.HumanoidRootPart.CFrame = MapSpawn3.CFrame

            elseif spawnPicker == 4 then
                char.HumanoidRootPart.CFrame = MapSpawn4.CFrame

            elseif spawnPicker == 5 then
                char.HumanoidRootPart.CFrame = MapSpawn5.CFrame

            elseif spawnPicker == 6 then
                char.HumanoidRootPart.CFrame = MapSpawn6.CFrame

            elseif spawnPicker == 7 then
                char.HumanoidRootPart.CFrame = MapSpawn7.CFrame

            elseif spawnPicker == 8 then
                char.HumanoidRootPart.CFrame = MapSpawn8.CFrame
            end
        end

        if InRound == false then

            for _, competitor in pairs(game.Players:GetChildren()) do
                competitor.Character:LoadCharacter()
            end

        end
    end
end)




while true do

    local bannerTextValue = game:GetService("ReplicatedStorage").Status

    local IntermissionMusic = game.Workspace.Music.IntermissionMusic
    IntermissionMusic.Playing = true
    --Intermission
    repeat
        InRound.Value = false
        intermission = intermission - 1
        wait(1)
        bannerTextValue.Value = "Intermission: ".. intermission 

    until intermission == 0 

    IntermissionMusic.Playing = false
    --Game starts
    if intermission == 0 then
        repeat

            InRound.Value = true

            spawn(function()
                local BombCopy = Bomb:Clone()
                BombCopy.Parent = game.Workspace.Bombs
                local xPosition = math.random(-64, 64)
                local zPosition = math.random(-64, 64)
                BombCopy.Position = Vector3.new(xPosition, 100, zPosition)
                wait(4)
            end)

            spawn(function()
                local CoinCopy = Coin:Clone()
                CoinCopy.Parent = game.Workspace.Coins
                local xPosition = math.random(-64, 64)
                local zPosition = math.random(-64, 64)
                CoinCopy.Position = Vector3.new(xPosition, 100, zPosition)
                wait(6)
            end)

            wait(1)
            gameTime = gameTime - 1
            bannerTextValue.Value = "Game Time left: " .. gameTime

        until gameTime == 0    
    end

    local function CleanUpGame()
        local TerrainRegenerationPart = game.Workspace.TerrainRegenerationPart
        local MapBackup = game.ServerStorage.MapBackup

        game.Workspace.Map:Destroy()

        for _, coinObject in pairs(game.Workspace.Coins:GetChildren()) do
            coinObject:Destroy()
        end

        for _, Bomb in pairs(game.Workspace.Bombs:GetChildren()) do
            Bomb:Destroy()
        end

        game.Workspace.Terrain:FillBlock(
            TerrainRegenerationPart.CFrame,
            TerrainRegenerationPart.Size,
            Enum.Material.Grass
        )

        local MapClone = MapBackup:Clone()
        MapClone.Parent = game.Workspace
        MapClone.Name = "Map"


    end

    --reset intermission and gameTime to their regular values and clean up map

    intermission = 30
    gameTime = 60
    CleanUpGame()
end

1 answer

Log in to vote
0
Answered by 3 years ago

I believe your problem is that you used:

   for _, competitor in pairs(game.Players:GetChildren()) do
                competitor.Character:LoadCharacter()
            end

You used LoadCharacter() which only loads the character not actually kill them. Instead, try killing them or setting their position to the place they spawn. It should look like this:

  for _, competitor in pairs(game.Players:GetChildren()) do
                competitor.Character.HumanoidRootPart.CFrame = game.Workspace[name of the spawn location].CFrame
            end

or

  for _, competitor in pairs(game.Players:GetChildren()) do
                competitor.Character.Humanoid.Health = 0
            end
Ad

Answer this question