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

What is wrong with this?

Asked by 9 years ago

Ok.. So I've been working on a snowball fight game as a basic project to start my scripting on, but for some reason my code doesn't work! My dev console dosen't find a problem, but it won't run. Can somebody help me?

while true do
    player = game.Players:GetPlayers()
    wait (5)
    for i = 1, # player do
        infogui = player[i].PlayerGui.infogui.Text
        infogui.Text = "Intermission"
    end
    wait(5)
    for i = 1, # player do
        infogui = player[i].PlayerGui.infogui.Text
        infogui.Text = "The game will start in a few."
    end
    wait(1)
    Number = 1

        for i = 1, # player do
        infogui.Text = "Loading map."
        player[i].Character.Parent = game.Workspace.Players
        print(player[i].Character)
        end
        mapchoise = "Map" .. Number
        print(mapchoise)
        local map1 = game.ServerStorage:FindFirstChild(mapchoise):Clone()
        map1.Parent = game.Workspace.RM
        wait (1)
        for i = 1, # player do
        infogui.Text = "Game in progress."
        spawnloc = math.random(1,4)
        if spawnloc == 1 then
            player[i].Character:MoveTo(map1.Spawn.Position)
        end
        if spawnloc == 2 then
        player[i].Character:MoveTo(map1.Spawn2.Position)
        end
        if spawnloc == 3 then
        player[i].Character:MoveTo(map1.Spawn3.Position)
        end
        if spawnloc == 4 then
        player[i].Character:MoveTo(map1.Spawn4.Position)
        end
        game.ServerStorage.SnowBall:Clone().Parent = player[i].Backpack
        end
        repeat
            wait(0.1)
        until game.Workspace.Players:GetChildren() == 1
    for i = 1, # player do  
    player[1]:LoadCharacter()
    infogui.Text = "Game Over!"
    end
    game.Workspace.RM:ClearAllChildren()
    end
0
Also, It prints the map, BUT IT DOES NOTHING ELSE colinthewierd 10 — 9y

1 answer

Log in to vote
0
Answered by 9 years ago

I found 1 simple mistake that is easy to fix. You had an if then statement that is defined correctly but then you kept doing if so it was making choices based on what you defined. So I went ahead and changed it, but can't test it unless I had the maps you had.

if spawnloc == 1 then
            player[i].Character:MoveTo(map1.Spawn.Position)
        end
        elseif spawnloc == 2 then
        player[i].Character:MoveTo(map1.Spawn2.Position)
        end
       elseif spawnloc == 3 then
        player[i].Character:MoveTo(map1.Spawn3.Position)
        end
       elseif spawnloc == 4 then
        player[i].Character:MoveTo(map1.Spawn4.Position)
        end

I have also noticed that towards the end you had player[1]:LoadCharacter() since you already defined 1 as i, you should make it

player[i]:LoadCharacter()
0
Thanks for the Reminder for the LoadCharacter Part, but the other spawnloc thing doesn't work :/ It's says "Expected End to close Do At line 26 go elseif" :( colinthewierd 10 — 9y
Ad

Answer this question