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

My intermission system is broken and I don't know why?

Asked by 3 years ago

This script used to work, then I tried adding a way to check if there is 2 or more players and the status never changed. I'll put comments everywhere to explain what the part of the script does, and tell me which part is broken. Thanks!

-- Variables are set up here
local IntermissionLength = 10
local RoundLength = 10

local InRound = game.ReplicatedStorage.InRound
local Status = game.ReplicatedStorage.Status

local HomePlatform = game.Workspace.HomePlatform
local TilePlatform = game.Workspace.TilePlatform

-- Checks if InRound is changed, and teleports them to the area they get teleported to.
InRound.Changed:Connect(function()
    print(InRound.Value)
    if InRound.Value == true then
        for _, player in pairs(game.Players:GetChildren()) do
            local char = player.Character
            char.HumanoidRootPart.CFrame = TilePlatform.CFrame
        end

    elseif InRound.Value == false then
        for _, player in pairs(game.Players:GetChildren()) do
            local char = player.Character
            char.HumanoidRootPart.CFrame = HomePlatform.CFrame
        end
    end
end)

-- The intermission timer
local function Timer()

    --  Check if there are enough players (Where I'm 90 percent sure it went wrong)
    local plrcount = 0 

    game.Players.PlayerAdded:Connect(function()
        for i,v in pairs(game.Players:GetChildren()) do
            plrcount = plrcount + 1
        end
    end)

    while plrcount >= 1 do
        Status.Value = "Not enough players!"
        for i = IntermissionLength, 0, -1 do
            InRound.Value = false
            wait(1)
            Status.Value = "Intermission for "..i.." more seconds!"
        end

        for i = RoundLength, 0,-1 do
            InRound.Value = true
            wait(1)
            Status.Value = "Game going on for "..i.." more seconds!"
        end
    end

    while plrcount == 1 do
        Status.Value = "Not enough players!"
    end
end

1 answer

Log in to vote
0
Answered by
zane21225 243 Moderation Voter
3 years ago

Hi!

I noticed a few things that may lead to the issues you are getting!

On line 34, you only add to the plrcount if a new player joins the game.

A better way to do this would to remove this line entirely.

Here's that code:

-- Variables:
local IntermissionLength = 10
local RoundLength = 10

local InRound = game.ReplicatedStorage.InRound
local Status = game.ReplicatedStorage.Status

local HomePlatform = game.Workspace.HomePlatform
local TilePlatform = game.Workspace.TilePlatform

-- On inRound Changed:
InRound.Changed:Connect(function()
    print(InRound.Value)
    if InRound.Value == true then
        for _, player in pairs(game.Players:GetChildren()) do
            local char = player.Character
            char.HumanoidRootPart.CFrame = TilePlatform.CFrame
        end

    elseif InRound.Value == false then
        for _, player in pairs(game.Players:GetChildren()) do
            local char = player.Character
            char.HumanoidRootPart.CFrame = HomePlatform.CFrame
        end
    end
end)

-- Intermission:
local function Timer()
    local plrcount = 0 

        for i,v in pairs(game.Players:GetChildren()) do
        plrcount = plrcount + 1
        print(plrcount)
        end

    while plrcount >= 1 do
        Status.Value = "Not enough players!"
        for i = IntermissionLength, 0, -1 do
            InRound.Value = false
            wait(1)
            Status.Value = "Intermission for " ..i.. " more seconds!"
        end

        for i = RoundLength, 0,-1 do
            InRound.Value = true
            wait(1)
            Status.Value = "Game going on for " ..i.. " more seconds!"
        end
    end

    while plrcount <= 1 do
        Status.Value = "Not enough players!"
    end
end

If this helps you, please accept this answer!

Otherwise, LMK in this answer's replies!

Ad

Answer this question