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

Why doesnt this work? Gamescript not working at all.

Asked by 9 years ago

My game script doesnt work at all. It looks like everything should be all good but when i test it it doesnt even do anything.

-- Made by Bennymax3333

local timeleft = workspace:findFirstChild('timeleft')
local currentMap = workspace:findFirstChild('currentMap')
local _Teams = game:GetService'Teams'
local _Players = game:GetService'Players'


function countDown()
    spawn(function()
        for i = 120, 0, -1 do
            wait(1)
            timeleft.Value = i
        end
    end)
end

function gameStart()
    local players = _Players:GetPlayers()
    for i = 1, #players do
        local stats = players[i].PlayerGui.fullGui.everything.gamePlay.informer
        spawn(function() 
            stats.Text = 'New round beginning!'
            stats.FontSize = 'Size24'
            timeleft.Value = 120
            wait(1)
            stats.Text = ''
        end)
    end
end

local function splitPlayers()
    _Teams.Lobby:Destroy()
    local UseSecondTeam = false
    for i, v in ipairs(_Players:GetPlayers()) do
        if UseSecondTeam then
            v.TeamColor = _Teams["Cops"].TeamColor
        else
            v.TeamColor = _Teams["Criminals"].TeamColor
        end
        UseSecondTeam = not UseSecondTeam
    end
end

function createTeams()
    local Cops = Instance.new("Team", _Teams)
    Cops.TeamColor = BrickColor.new("Bright blue") -- Note that TeamColor is a BrickColor value
    Cops.Name = "Cops"
    Cops.AutoAssignable = false

    local Criminals = Instance.new("Team", _Teams)
    Criminals.TeamColor = BrickColor.new("Bright orange")
    Criminals.Name = "Criminals"    
    Criminals.AutoAssignable = false
end

function teleportPlayers()

    -- Teleport Players to their spawn depending on which team they are on

    local players = _Players:GetPlayers()

    local copSpawn = workspace.teleportationpart
    local criminalSpawn = workspace.teleportationpart2


    for i = 1, #players do
        if players[i].TeamColor == BrickColor.new("Bright blue") then
            players.Character.Torso.CFrame = CFrame.new(copSpawn.Position)
        elseif players[i].TeamColor == BrickColor.new("Bright orange") then
            players.Character.Torso.CFrame = CFrame.new(criminalSpawn.Position)
        end
    end
end

function waitSome()
    local players = _Players:GetPlayers()
    for i = 1, #players do
        local stats = players[i].PlayerGui.fullGui.everything.gamePlay.informer
        spawn(function()
            stats.FontSize = 'Size24'
            stats.Text = "Intermission! Check our the shop and talk to your friends!"
            wait(30)
            stats.Text = ''
        end)
    end
end


function endGame()
    local players = _Players:GetPlayers()
    for i = 1, #players do
        players[i]:LoadCharacter()
    end
    currentMap:ClearAllChildren()
end



function goAhead()
    local players = _Players:GetPlayers()
    for i = 1, #players do
        players[i].PlayerGui.fullGui.everything.gamePlay.informer.Text = 'We have enough players to start!'
    end
end


function chooseMap()
    -- Chooses a new map
    -- Stuff to Add: Make it so it removes the old map
    local oldmap = game.Workspace.currentMap:GetChildren()
    oldmap:remove()
    local maps = game.ServerStorage.Maps:GetChildren()
    local clone = maps[math.random(1, #maps)]
    clone.Parent = currentMap
end

-- So this ending function is a bit messed up
-- Remember how your game works:

-- [1] If there is enough players, start the game
-- [2] Wait for the game to finish
-- [3] Cleanup
-- [4] Intermission
-- Back to step [1]




while wait() do -- Every "server frame" (kind of, dn't hurt me ScriptingHelpers!)
    if _Players.NumPlayers >= 2 then
        goAhead() -- Tell all players we have enough players to start!
        createTeams() -- Create the Cops and Criminals teams
        splitPlayers() -- Assign each player to one of these teams
        chooseMap() -- Put a new map into currentMap
        gameStart() -- Tell everyone the game is starting and set timeleft to 120 seconds
        teleportPlayers() -- Teleport all players to their spawn

        -- We need to add something to wait for the round to end
        -- I recommend using a while true do loop like so:


        while timeleft.Value > 0 do -- The round is still going
            wait()

        -- Past here runs after the round ended







        if workspace.NoCash.Value == true then
            timeleft.Value = 0
            end --Should this be 120?
            countDown() -- Sets the time to 120 and counts down
            endGame() -- Respawn all Players, remove the currentMap
            waitSome() -- Wait 30 seconds for intermission
        end
    else -- If there is only one player, don't start the game
        local player = _Players:GetPlayers()[1]

        player.PlayerGui.fullGui.everything.gamePlay.informer.Text = '2 players are needed to start! Invite a friend.'


    end
end

Did i spell something wronge ore what!? I thought it looked perfect but for some reaason it doesnt work at all! PLEASE HELP ME I DONT KNOW WHAT TO DO?!

2 answers

Log in to vote
2
Answered by 9 years ago

Try to use WaitForChilds to make sure that everything is where it should be at the right time. Check the developer console for any outputs, try debugging by using print statements to find out how far your code has got before getting stuck.

Ad
Log in to vote
0
Answered by
Proflts 15
9 years ago

Capitalize Workspace on line one and line 2. thats all i got.

Answer this question