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

What's the error to this script? (No output problems)

Asked by 10 years ago

The script is long, sorry if you have to read all of it. I just can't find what's wrong with the script, please help.

Maps = {"Wobbly Bridge", "Tower of Magic"}
randomMap = Maps[math.random(#Maps)]

Players = game.Players:GetPlayers() 
NumP = game.Players.NumPlayers() 
L = game.Lighting:GetChildren() 
TimeOfRound = 160 
MLength = 1 
IntermissionTime = 30 
MessageTBS = "Seconds Left: " 

function mapchose()
    local m = Instance.new("Message", workspace)
    m.Text = "You will be playing on the "..randomMap.." map."
    wait(MLength)
    m:Destroy()
    L:findFirstChild(randomMap):Clone().Parent = workspace
end

function int()
    local m = Instance.new("Message", Workspace)
    a = IntermissionTime
    for i = 1,IntermissionTime do
        wait(1)
        m.Text = "Intermission, "..MessageTBS..tostring(a)-1        
    end
    m:Destroy()
end

BrightBlue={}
BrightRed={}

function assign()
    local Quarter = math.floor(Game.Players.NumPlayers/2)
    local Players = Game.Players:GetPlayers()
    for i = 1, #Players do
        local random = table.remove(Players, math.random(#Players))
        if i <= Quarter then 
            random.TeamColor = BrickColor.new("Bright red")
            table.insert(BrightRed,random)
        else
            random.TeamColor = BrickColor.new("Bright blue")
            table.insert(BrightBlue,random)
        end
    end
end

function round()
    for i = 1,TimeOfRound do
        wait(1)
        for i,v in pairs(Players) do
            if v.WipeOuts.Value >10 then
                for i, z in ipairs(BrightBlue) do
                    if (not z) or v == z then
                        table.remove(BrightBlue,i)
                    end
                end
                for i, z in ipairs(BrightRed) do
                    if (not z) or v == z then
                        table.remove(BrightRed,i)
                    end
                end
            end
        end
    end
end

function winner()
    if #BrightBlue == #BrightRed then
        local m = Instance.new("Message", workspace)
        m.Text = "The teams have tied!"
        wait(MLength)
        m:Destroy()
    elseif #BrightBlue > #BrightRed then
        local m = Instance.new("Message", workspace)
        m.Text = "The Blue Team has won!"
        wait(MLength)
        m:Destroy()
    elseif #BrightRed > #BrightBlue then
        local m = Instance.new("Message", workspace)
        m.Text = "The Red Team has won!"
        wait(MLenght)
        m:Destroy()
    end 
end

while true do
    if NumP >= 2 then
        int()
        mapchose()
        assign()
        round()
        winner()
    else
        local m = Instance.new("Message", workspace)
        m.Text = "This game requires 2+ players!"
        wait(MLength)
        m:Destroy()
    end
end


3 answers

Log in to vote
0
Answered by
Shawnyg 4330 Trusted Badge of Merit Snack Break Moderation Voter Community Moderator
10 years ago

I fixed up most of your errors and added comments.

Maps = {"Wobbly Bridge", "Tower of Magic"}
randomMap = Maps[math.random(#Maps)]

Players = game.Players:GetPlayers() 
NumP = game.Players.NumPlayers -- It's not a Method, so you don't need '()'
L = game.Lighting:GetChildren() 
TimeOfRound = 160 
MLength = 1 
IntermissionTime = 30 
MessageTBS = "Seconds Left: " 

function mapchose()
    local m = Instance.new("Message", workspace)
    m.Text = "You will be playing on the "..randomMap.." map."
    wait(MLength)
    m:Destroy()
    L:findFirstChild(randomMap):Clone().Parent = workspace
end

function int()
    local m = Instance.new("Message", Workspace)
    a = IntermissionTime
    for i = 1,IntermissionTime do
        wait(1)
        m.Text = "Intermission, "..MessageTBS..tostring(a)-1        
    end
    m:Destroy()
end

BrightBlue={}
BrightRed={}

function assign()
    local Quarter = math.floor(NumP/2)
    local Players = Game.Players:GetPlayers()
    for i = 1, #Players do
        local random = table.remove(Players, math.random(#Players))
        if i <= Quarter then 
            random.TeamColor = BrickColor.new("Bright red")
            table.insert(BrightRed,random)
        else
            random.TeamColor = BrickColor.new("Bright blue")
            table.insert(BrightBlue,random)
        end
    end
end

function round()
    for i = 1,TimeOfRound do
        wait(1)
        for i,v in pairs(Players) do
            if v.leaderstats.WipeOuts.Value >10 then -- Needed to add leaderstats
                for i, z in ipairs(BrightBlue) do
                    if (not z) or v == z then
                        table.remove(BrightBlue,i)
                    end
                end
                for i, z in ipairs(BrightRed) do
                    if (not z) or v == z then
                        table.remove(BrightRed,i)
                    end
                end
            end
        end
    end
end

function winner()
    if #BrightBlue == #BrightRed then -- I feel there's something rong with this, but I'm not an expert on tables. Consider doing this a different way.
        local m = Instance.new("Message", workspace)
        m.Text = "The teams have tied!"
        wait(MLength)
        m:Destroy()
    elseif #BrightBlue > #BrightRed then
        local m = Instance.new("Message", workspace)
        m.Text = "The Blue Team has won!"
        wait(MLength)
        m:Destroy()
    elseif #BrightRed > #BrightBlue then
        local m = Instance.new("Message", workspace)
        m.Text = "The Red Team has won!"
        wait(MLength) -- You mispelled 'Length'
        m:Destroy()
    end 
end

while true do
    if NumP >= 2 then
        int() --I recomened adding some wait times in between the calling of the functions, because if you call it all at once, you'll get a bunch of messages which would generate some lag.
        mapchose()
        assign()
        round()
        winner()
    else
        local m = Instance.new("Message", workspace)
        m.Text = "This game requires 2+ players!"
        wait(MLength)
        m:Destroy()
    end
end



Ad
Log in to vote
0
Answered by
samfun123 235 Moderation Voter
10 years ago

I think your problem is on line 5 which is trying to get the number of players :

NumP = game.Players.NumPlayers() 

The problem is that game.Players.NumPlayers() isn't a function. Its a property that stores a number.

To fix this just change line 5 to :

NumP = game.Players.NumPlayers

The second problem is that with your while true do loop you don't update the NumP value or check it again. So if a player leaves or joins the game doesn't know that.

I recommend to just add the "NumP =" code I gave you in the loop but not in the if statement.

Correct code :

while true do
    NumP = game.Players.NumPlayers
    if NumP >= 2 then
        int()
        mapchose()
        assign()
        round()
        winner()
    else
        local m = Instance.new("Message", workspace)
        m.Text = "This game requires 2+ players!"
        wait(MLength)
        m:Destroy()
    end
end

I believe I have missed some things and I would recommend checking out the other answers for things I might have missed.

If you have any questions, concerns or just need some help with this PM me on ROBLOX!

0
I don't know any other ways to fix that @ShawnyG BugQuestioner -4 — 10y
Log in to vote
0
Answered by
Ekkoh 635 Moderation Voter
10 years ago

I noted on line 6 you have

L = game.Lighting:GetChildren()

and then on line 17 you try to call FindFirstChild on the children of Lighting, which you can't do.

L:findFirstChild(randomMap):Clone().Parent = workspace

What I would do is set L to just game.Lighting rather than game.Lighting:GetChildren().

L = game.Lighting

Answer this question