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

Script sometimes works but other times it doesn't work, not getting errors?

Asked by 7 years ago
Edited 7 years ago

This script teams the player to Playing and in X amount of seconds respawns them in the lobby, for some reason when respawning the players so they can go onto the games map it doesn't work while other times it works. game https://www.roblox.com/games/1352607389/DominatedLegacys-Place-Number-240

--Variables
local Map = game.Workspace.Map
local Lobby = game.Workspace
local ZLobby = game.Teams.ZLobby
local TextValue = game.ReplicatedStorage:WaitForChild("TextValue")
local Sounds = game.Workspace.Sounds
local NewSound = Instance.new("Sound")
local maps = game.ReplicatedStorage:WaitForChild("Maps")
local gametime = 5









local function Reward()

        for _, player in pairs(game.Players:GetPlayers()) do
                    player.Playing.Value = true
                    if player.Playing.Value == true then
                        player.Cash.Value = player.Cash.Value + 15
                    else
                        print("Didn't play that round")

                    end

                end

end

local function NoReward()

        for _, player in pairs(game.Players:GetPlayers()) do
                    player.Playing.Value = false



                end

end


local function LoadMap()
    local mapList = maps:GetChildren() 
    local selectedIndex = math.random(1,#mapList)
    local map = mapList[selectedIndex]:Clone()
    map.Parent = game.Workspace.Map

end

local function UnLoadMap()
    game.Workspace.Map:ClearAllChildren()
end



local function main()
for i = 15,0,-1 do
        TextValue.Value = "Intermission: "..i
        wait(1)
        if i == 0 then
            LoadMap()
                Reward()


        end
    end


local function setTeam(player, teamName)
    player.TeamColor = game.Teams[teamName].TeamColor

    end




for _, player in pairs(game.Players:GetPlayers()) do
    setTeam(player, "Playing")
player:LoadCharacter()  


    end

wait(4)
for _, player in pairs(game.Players:GetPlayers()) do
    setTeam(player, "ZLobby")

    end




    TextValue.Value = "Game In Progress"
    wait(10)
    NoReward()  

    UnLoadMap()

for _,v in pairs(game.Players:GetPlayers()) do 

v:LoadCharacter()
end
    TextValue.Value = "Game Over!"
    NewSound.Parent = game.Workspace.Sounds
    Sounds.Sound.SoundId = "rbxassetid://1257883449"
    Sounds.Sound.Volume = 2
    Sounds.Sound.Playing = true

    wait(8.5)
    Sounds.Sound:remove()
    TextValue.Value = ""

end



while wait(gametime)do
main()

end







1 answer

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

Try this

--Variables
local Map = game.Workspace.Map
local Lobby = game.Workspace
local ZLobby = game.Teams.ZLobby
local TextValue = game.ReplicatedStorage:WaitForChild("TextValue")
local Sounds = game.Workspace.Sounds
local NewSound = Instance.new("Sound")
local maps = game.ReplicatedStorage:WaitForChild("Maps")
local gametime = 5


local function Reward()

        for _, player in pairs(game.Players:GetPlayers()) do
                    player.Playing.Value = true
                    if player.Playing.Value == true then
                        player.Cash.Value = player.Cash.Value + 15
                    else
                        print("Didn't play that round")

                    end
           end
end

local function NoReward()

        for _, player in pairs(game.Players:GetPlayers()) do
                    player.Playing.Value = false

                end
end


local function LoadMap()
    local mapList = maps:GetChildren() 
    local selectedIndex = math.random(1,#mapList)
    local map = mapList[selectedIndex]:Clone()
    map.Parent = game.Workspace.Map

end

local function UnLoadMap()
    game.Workspace.Map:ClearAllChildren()
end



local function main()
for i = 15,0,-1 do
        TextValue.Value = "Intermission: "..i
        wait(1)
        if i == 0 then
            LoadMap()
                Reward()

        end
    end


local function setTeam(player, teamName)
    player.TeamColor = game.Teams[teamName].TeamColor

    end

for _, player in pairs(game.Players:GetPlayers()) do
    setTeam(player, "Playing")
player:LoadCharacter()  


    end

wait(4)
for _, player in pairs(game.Players:GetPlayers()) do
    setTeam(player, "ZLobby")

    end

    TextValue.Value = "Game In Progress"
    wait(10)
    NoReward()  

    UnLoadMap()

for _,v in pairs(game.Players:GetPlayers()) do 

v:LoadCharacter()
end
    TextValue.Value = "Game Over!"
    NewSound.Parent = game.Workspace.Sounds
    Sounds.Sound.SoundId = "rbxassetid://1257883449"
    Sounds.Sound.Volume = 2
    Sounds.Sound.Playing = true

    wait(8.5)
    Sounds.Sound:remove()
    TextValue.Value = ""

end

while wait(gametime)do
main()
LoadMap()
end
Ad

Answer this question