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

Script Doesn't Work?

Asked by 9 years ago

Here is my script: It all works smoothly until line 103. ScriptAnalysis has found no problems with it. I'm pretty sure the problem is with the variables, but I'm not certain. Help?

script.Parent.Disabled = true

local playerstorage = game:GetService("Players")
local storage = game:GetService("ServerStorage")
local guifolder = storage.Guis
local players = {}
local holder = game.Workspace:WaitForChild("MapHolder")
local maps = game.Lighting:WaitForChild("Maps")
local message = game.Lighting.Message
local roundtime = 60 * 5


for _, player in pairs(game.Players:GetPlayers()) do
  local humanoid = player.Character:WaitForChild("Humanoid")
  if humanoid and humanoid.Health > 0 then
    table.insert(players, player)
  end
end



message.Value = "Map Being Chosen..."

holder:ClearAllChildren()
wait(2) 

local allmaps = maps:GetChildren()
local newmap = allmaps[math.random(1, #allmaps)]
newmap:Clone().Parent = holder
print 'Map put!'
wait(2)

-- Tell players the map!


if (holder:FindFirstChild("Warehouse")) then

    message.Value = "Map Chosen: Space Warehouse"
    wait(5)
end

    -- Alien Only!
  local alien = table.remove(players, math.random(#players))
  local alieng = guifolder.Alien
  local alieng2 = alieng:Clone()
  alieng2.Parent = alien.PlayerGui

  for _, player in pairs(players) do
    -- only into non-aliens!
    print(player)
    guifolder.Soldier:Clone().Parent = player.PlayerGui
  end

-- TP the players!


for _, player in pairs(game.Players:GetPlayers()) do
  local humanoid = player.Character:WaitForChild("Humanoid")
  if humanoid and humanoid.Health > 0 then
    table.insert(players, player)
  end
end


local spawnmodel =  newmap:WaitForChild("Spawns")
local spawns = spawnmodel:GetChildren()
for _, player in pairs(players) do
    if player and player.Character and #spawns > 0 then
        local Torso = player.Character:WaitForChild("Torso")
        local spawnindex = math.random(1, #spawns)
        local spawn = spawns[spawnindex]
        if spawn and Torso then
            table.remove(spawns, spawnindex)
            Torso.CFrame = CFrame.new(spawn.Position + Vector3.new(0, 3, 0))

                local activetag = Instance.new("StringValue")
                activetag.Name = "activetag"
                activetag.Parent = player.Character         

        end
    end
end

message.Value = "Round In Progress"


-- TIMER

local localtimer = roundtime
while localtimer > 0 do     
    wait(1)
    localtimer = localtimer - 1
    message.Value = "Round Time Left: (" .. localtimer .. ")"

    activeplayers = {}
    alienactive = false

    local player = math.random(1, #players)

    for _, players in pairs(players) do

        if player then          
            local character = player.Character
            if character then
                local activetag = character:FindFirstChild("activetag")
                local humanoid = character:FindFirstChild("Humanoid")
                if activetag and humanoid and humanoid.Health > 0 then
                    alienactive = true
                    end
                    table.insert(activeplayers, player)
                    break
                end
            end
        if #activeplayers <=1 or not alienactive then
            break
        end
    end

end

local gameresults = "The Alien Lost!"

if alienactive then
     if #players > 2 then
        --alien failed!
        message.Value = gameresult
    else
        gameresult = "The Alien Has Killed Everybody!"
        message.Value = gameresult
    end
else
    --Alien Captured
end

--TP THEM BACK!!!

local lobbyspawns = {}
local lobby = game.Workspace.Lobby
 for _, v in pairs(game.Workspace:WaitForChild("Lobby")) do
    if v and v.Name == "spawn" then
        table.insert(lobbyspawns, v)
    end
end

for _, player in pairs(activeplayers) do
    if player then
        if player.Character then
            local humanoid = player.Character.Humanoid
            if humanoid then
                humanoid:UnequipTools()
            end
        end
        local randomspawn = lobbyspawns[math.random(1, #lobbyspawns)]
        player.Character:MoveTo(randomspawn.Position)
        local backpack = player:FindFirstChild("Backpack")
        if backpack then
            backpack:ClearAllChildren()
        end
    end
end

script.Parent.Disabled = false
script.Disabled = true



Answer this question