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

Game round loop? script is not repeating

Asked by 4 years ago

Hello.

I recently started making a round-based game called 'Jeff'. But after 1 round, my script doesn't return to the start (picking a map, killer etc) it just loops the gameplay. Can somebody help me?

There is a normal script and a module script, both in server script service

Normal script:

while true do
--repeat wait() until game.Players.NumPlayers >= 2 

local IntermissionRoundRemote = game.ReplicatedStorage:WaitForChild("IntermissionFrame")
local LightningOfKiller = game.ReplicatedStorage:WaitForChild("LightningOfJeff")
local Round = require(script:WaitForChild("Intermission"))

while wait() do

Round.Intermission()
Round.Calibrate()
game.ReplicatedStorage.Status.Value = "Game starting soon!"

wait(2.5)

Round.ChooseTheJeff()

wait(2.5)

Round.ChooseTheMap()

wait(1)

game.ReplicatedStorage.Status.Value = "Map loaded!"

wait(2.5)

game.ReplicatedStorage.Status.Value = "Intermission..."
game.Workspace.GameMusic.Boom:Play()

wait(2.5)

IntermissionRoundRemote:FireAllClients(game.Players:GetChildren())

Round.StartTheGame()

wait(3)

local PLRS = {}

for i, v in pairs(game.Players:GetChildren()) do
    if v then
        table.insert(PLRS, v)

        if v.Name == game.ReplicatedStorage.KillerName.Value then
            table.remove(PLRS, i)
        end
    end
end

local function toMS(s)
    return ("i:i"):format(s/60%60, s%60)
end

    for Countdown = 180,0,-1 do
        game.ReplicatedStorage.Status.Value = toMS(Countdown).." left!"
        wait(1)

        if #PLRS == 0 then
            game.ReplicatedStorage.Status.Value = "All Players have died!"

            wait(2)

            for i, Song in pairs(game.Workspace.GameMusic:GetChildren()) do
                                                if Song then
                                                    Song:Stop()
                                                end
                                            end

                                            game.ReplicatedStorage.LightningOfJeffBack:FireClient(game.Players:FindFirstChild(game.ReplicatedStorage.KillerName.Value))

            for i, v in pairs(game.Players:GetChildren()) do
                if v then
                    v:LoadCharacter()

                    game.Players:FindFirstChild(game.ReplicatedStorage.KillerName.Value).leaderstats.Money.Value = game.Players:FindFirstChild(game.ReplicatedStorage.KillerName.Value).leaderstats.Money.Value + 50

                    v.Character.HumanoidRootPart.CFrame = game.Workspace.MenuTeleportPart.CFrame + Vector3.new(0, 10, 0)

                    if game.Workspace:FindFirstChild("Store") then
                        game.Workspace.Store:Destroy()
                    end

                    if game.Workspace:FindFirstChild("Forest") then
                        game.Workspace.Forest:Destroy()
                    end

break

                else

                    if Countdown == 0 then

                        game.ReplicatedStorage.Status.Value = "Time's up!"

                        wait(2)

                        for i, Song in pairs(game.Workspace.GameMusic:GetChildren()) do
                                                if Song then
                                                    Song:Stop()
                                                end
                                            end

                                            game.ReplicatedStorage.LightningOfJeffBack:FireClient(game.Players:FindFirstChild(game.ReplicatedStorage.KillerName.Value))

                        for i, v in pairs(game.Players:GetChildren()) do
                            if v then
                                v:LoadCharacter()

                            v.Character.HumanoidRootPart.CFrame = game.Workspace.MenuTeleportPart.CFrame + Vector3.new(0, 10, 0)

                            if game.Workspace:FindFirstChild("Store") then
                        game.Workspace.Store:Destroy()
                    end

                    if game.Workspace:FindFirstChild("Forest") then
                        game.Workspace.Forest:Destroy()
                    end

                                break
                            else
                                if not game.Players:FindFirstChild(game.ReplicatedStorage.KillerName.Value) then

                                    game.ReplicatedStorage.Status.Value = "Killer has left!"

                                    for i, Song in pairs(game.Workspace.GameMusic:GetChildren()) do
                                                if Song then
                                                    Song:Stop()
                                                end
                                            end

                                    wait(2)

                                    for i, v in pairs(game.Players:GetChildren()) do
                                        if v then
                                            v:LoadCharacter()

                                            v.Character.HumanoidRootPart.CFrame = game.Workspace.MenuTeleportPart.CFrame + Vector3.new(0, 10, 0)

                                            if game.Workspace:FindFirstChild("Store") then
                        game.Workspace.Store:Destroy()
                    end

                    if game.Workspace:FindFirstChild("Forest") then
                        game.Workspace.Forest:Destroy()
                    end
break

                                    else
                                        if #PLRS >= 0 and Countdown == 0 then

                                            game.ReplicatedStorage.Status.Value = "Killer didn't kill every player!"

                                            for i, Song in pairs(game.Workspace.GameMusic:GetChildren()) do
                                                if Song then
                                                    Song:Stop()
                                                end
                                            end 
                                            wait(3)

                                            for i, v in pairs(PLRS) do
                                                if v then
                                                    v.leaderstats.Money.Value = v.leaderstats.Money.Value + 50

                                                    game.ReplicatedStorage.LightningOfJeffBack:FireClient(game.Players:FindFirstChild(game.ReplicatedStorage.KillerName.Value))

                                                    for i, x in pairs(game.Players:GetChildren()) do
                                                        if x then

                                                            x.Character.HumanoidRootPart.CFrame = game.Workspace.MenuTeleportPart.CFrame + Vector3.new(0, 10, 0)


                                                if game.Workspace:FindFirstChild("Store") then
                        game.Workspace.Store:Destroy()
                    end

                    if game.Workspace:FindFirstChild("Forest") then
                        game.Workspace.Forest:Destroy()
                    end

                                                break

                                                        end
                                                    end
                                                end
                                            end

                                        end
                                    end

                                end
                            end
                        end
                    end
                end
            end
        end
    end

    for FreeTime = 20,0,-1 do
        game.ReplicatedStorage.Status.Value = "Waiting for new mission! "..FreeTime
        wait(1)
    end
    end

end
end

Module script (Inside of normal script)

local module = {}

local KillerChosen
local KillerInWorkspace 
local MapChosen
local PLRS = {}

local LightningOfKiller = game.ReplicatedStorage.LightningOfJeff

function module.Calibrate()
    for i, v in pairs(game.Players:GetChildren()) do
        if v then
            table.insert(PLRS, v)
        end
    end
end

function module.Intermission()
    for i = 20,0,-1 do
        game.Workspace.GameMusic.Tick:Play()
        game.ReplicatedStorage.Status.Value = "Game starting in "..i.." seconds!"
        wait(1)
    end
end

function module.ChooseTheJeff()

    game.ReplicatedStorage.Status.Value = "Choosing the killer..."

    wait(2.5)   
    local Jeff = PLRS[math.random(1,#PLRS)]

    if Jeff ~= nil then
        game.ReplicatedStorage.Status.Value = "The killer is "..Jeff.Name.."!"

        KillerChosen = Jeff

        for i, PLRSONE in pairs(PLRS) do
            if PLRSONE == Jeff then
                table.remove(PLRS, i)
            end
        end

    else
        game.ReplicatedStorage.Status.Value = "The killer"..Jeff.Name.." left!"

        game.ReplicatedStorage.KillerName.Value = ""
        Jeff = ""
        KillerChosen = ""
    end

    game.ReplicatedStorage.KillerName.Value = KillerChosen.Name

end

function module.ChooseTheMap()

    game.ReplicatedStorage.Status.Value = "Choosing the map..."

    wait(2.5)

    local Maps = game.ServerStorage.Maps:GetChildren()

    local ChosenMap = Maps[math.random(1,#Maps)]

    if ChosenMap ~= nil then
        game.ReplicatedStorage.Status.Value = "The map is "..ChosenMap.Name.."!"

        MapChosen = ChosenMap
    else
        game.ReplicatedStorage.Status.Value = "Failed to choose the map..."
    end

    wait(2)

    game.ReplicatedStorage.Status.Value = "Waiting for map to load..."

    ChosenMap.Parent = workspace

    wait(1)

end

function module.StartTheGame()

    game.ReplicatedStorage.Status.Value = "Teleporting survivors on the map"

    for i, v in pairs(PLRS) do
        if v then
            local HRP = v.Character:FindFirstChild("HumanoidRootPart")

            if not HRP then
                table.remove(PLRS, i)
            end

            local Spawners = MapChosen:FindFirstChild("SpawnPoints"):GetChildren()

            if Spawners then
                HRP.CFrame = Spawners[1].CFrame + Vector3.new(0, 6, 0)
                table.remove(Spawners, 1)
            end
        end
    end

    KillerChosen.Character["Body Colors"].HeadColor = BrickColor.White()
    KillerChosen.Character["Body Colors"].LeftArmColor = BrickColor.White()
    KillerChosen.Character["Body Colors"].RightArmColor = BrickColor.White()
    KillerChosen.Character["Body Colors"].LeftLegColor = BrickColor.White()
    KillerChosen.Character["Body Colors"].RightLegColor = BrickColor.White()
    KillerChosen.Character["Body Colors"].TorsoColor = BrickColor.White()
    KillerChosen.Character.Head.face.Texture = game.ServerStorage.JeffFace.Value
    KillerChosen.Character.Shirt.ShirtTemplate = game.ServerStorage.JeffShirt.Value
    KillerChosen.Character.Pants.PantsTemplate = game.ServerStorage.JeffPants.Value

    wait(2.5)

    for Countdown = 15,0,-1 do
        game.ReplicatedStorage.Status.Value = "Hide! The killer will be here in "..Countdown.." seconds!"
        wait(1)
    end

    game.ReplicatedStorage.Status.Value = "Hide! The killer is coming!"

    wait(2.5)

    local Songs = {game.Workspace.GameMusic.Music1, game.Workspace.GameMusic.Music2, game.Workspace.GameMusic.Music3, game.Workspace.GameMusic.Music4}

    local ChosenGameSong = Songs[math.random(1,#Songs)]
    ChosenGameSong:Play()

    if not KillerChosen then
        game.ReplicatedStorage.Status.Value = "The killer has left! Reojoin the game because im an idiot and i dont know what do i do :DDDD"
    else
        KillerChosen.Character:FindFirstChild("HumanoidRootPart").CFrame = MapChosen.KillerSpawn.CFrame + Vector3.new(0, 6, 0)
        local ClonedKnife = game.ServerStorage.Knife:Clone()

        ClonedKnife.Parent = KillerChosen.Backpack

        game.ReplicatedStorage.Status.Value = "The killer is on the map!"
    end

    LightningOfKiller:FireClient(KillerChosen)

end

return module

Thank you

0
Wouldn't you need more than 1 player to test this. That might be the problem. I honestly didn't read through the whole script, but try testing your game in a server test to see if it works. Sir_Ragealot 72 — 4y

1 answer

Log in to vote
0
Answered by
Ga7in6 5
4 years ago
Edited 4 years ago

Put a end) at the last line of each of those, that might help

Ad

Answer this question