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

My script isn't working correctly?

Asked by
Relatch 550 Moderation Voter
9 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.

This script is supposed to switch between maps every 30 seconds. For some reason, it's not doing that. It's not saying anything in output, and the text gui doesn't say anything either. Help?

for i,v in pairs(game.Players:GetChildren()) do
    local maps = game.ServerStorage:FindFirstChild("Maps")
    local gui = v.PlayerGui:FindFirstChild("MapAnnouncer")
    local guitext = gui:FindFirstChild("AnnouncerText")

    while true do
        wait(3)
        chosenmap = maps[math.random(1, #maps)]
        chosenmap.Parent = game.Workspace

        guitext.Text = "Map Chosen: " ..chosenmap.Name

        for i = 30, 0, -1 do
            if i <= 9 then
                game.Workspace.TimerCount:Play()
                guitext.Text = "New game starts in: (0:0"..i..")"
            else
                game.Workspace.TimerCount:Play()
                guitext.Text = "New game starts in: (0:"..i..")"
            end
            wait(1)
        end
    end
end

1 answer

Log in to vote
0
Answered by 9 years ago

Please provide explanation with your answers. Simply posting code does not spread knowledge of integral scripting processes which helps people understand the logic and reasoning behind your answer.

I changed the order of this script, let me know if there are any problems with it as I cannot test it.

while true do

    local maps = game.ServerStorage:FindFirstChild("Maps")
    chosenmap = maps[math.random(1, #maps)]
    chosenmap.Parent = game.Workspace

    --update all of the players gui text 
    for i,v in pairs(game.Players:GetChildren()) do 
        local gui = v.PlayerGui:FindFirstChild("MapAnnouncer")
        local guitext = gui:FindFirstChild("AnnouncerText")
        guitext.Text = "Map Chosen: " ..chosenmap.Name
    end

    for i = 30, 0, -1 do

        for i,v in pairs(game.Players:GetChildren()) do 
            local gui2 = v.PlayerGui:FindFirstChild("MapAnnouncer")
            local guitext2 = gui:FindFirstChild("AnnouncerText")


            if i <= 9 then
                guitext.Text = "New game starts in: (0:0"..i..")"
            else
                guitext.Text = "New game starts in: (0:"..i..")"
            end

        end

        game.Workspace.TimerCount:Play() -- play sound then wait
        wait(1)

    end

end
Ad

Answer this question