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

Gamemode picker not working?

Asked by 9 years ago

I have a gamemode picker and it picks a number instead of a gamemode.

while true do
    local gamemodes = {"Team Deathmatch", "Domination", "Capture The Flag"}
    game.Workspace.MessageHolder.Text = "2 Players are needed to start a round."
    wait(0)
    if game.Players.NumPlayers >= 2 then
        game.Workspace.MessageHolder.Text = "Intermission"
        wait(2)
local gamemode = math.random(1, #gamemodes) -- it picks a number instead of a gamemode
wait(2)
game.Workspace.MessageHolder.Text = "The Selected Game Mode is  " ..gamemode.. " !" -- this displays the picked number when I want it to show the picked gamemode
wait(2)
game.Workspace.MessageHolder.Text = "Starting..."
end
end
end

Help me please!

0
Updated my answer. Shawnyg 4330 — 9y

1 answer

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

Your problem is on line 8. You're telling the script to pick a number between 1, and the length of the table 'gamemodes'. To have it pick a value from the table, it would be local gamemode = gamemodes[math.random(1, #gamemodes)] You also put an extra end, which was unnecessary. Here is your full script:

while true do
    local gamemodes = {"Team Deathmatch", "Domination", "Capture The Flag"}
    game.Workspace.MessageHolder.Text = "2 Players are needed to start a round."
    wait(0)
    if game.Players.NumPlayers >= 2 then
        game.Workspace.MessageHolder.Text = "Intermission"
        wait(2)
        local gamemode = gamemodes[math.random(1, #gamemodes)] --It doesn't need to be local
        wait(2)
        game.Workspace.MessageHolder.Text = "The Selected Game Mode is  " ..gamemode.. " !"
        game.Workspace.MessageHolder.Text = "Starting..."
    end
end
0
There was an extra end because I took out part of the script for my question and forgot to take out the end. jimborimbo 94 — 9y
0
@jimborimbo, Well go ahead and add the end, to see if it works. Let me know if it errors! Shawnyg 4330 — 9y
Ad

Answer this question