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

How can I modify this script so It will keep giving you weapons until the round stops?

Asked by 2 years ago

Ello Developers!

As the title says, I am trying to modify this script so that It will keep giving the players weapons until the round stops

local RS = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local Folder = RS:WaitForChild("Melee")

local roundEvent = RS:WaitForChild('RoundEvent')
-- Change the "Folder" if you change the folder name in Replicated Storage

local function givePlayer(character)
    local Tools = Folder:GetChildren()
    local ToolsTable = Tools
    local chosenTools = {}

    repeat
        local selectedIndex = math.random(1, #ToolsTable)
        table.insert(chosenTools, ToolsTable[selectedIndex])
        table.remove(ToolsTable, selectedIndex)
    until #chosenTools >= 1
    -- Numbers of tools going to give

    local plr = Players:GetPlayerFromCharacter(character)
    for i,v in pairs(chosenTools) do
        Folder:FindFirstChild(v.Name):Clone().Parent = plr.Backpack
    end
end

roundEvent.Event:Connect(function()
    for _, plr in Players:GetChildren() do
        givePlayer(plr.Character)
        script.AlreadyHasMelee.Value = true
    end
end)

local function onAdded(player)
    player.CharacterAdded:Connect(givePlayer) -- Triggers when the player spawns or respawns
end

Players.PlayerAdded:Connect(onAdded)

The Script that fires "roundEvent"

local lobbyLocation = game.Workspace.SpawnLocation.Position + Vector3.new(0,3,0)



local ReplicatedStorage = game:GetService('ReplicatedStorage')

local timeEvent = ReplicatedStorage:WaitForChild('TimeEvent')

local roundEvent = ReplicatedStorage:WaitForChild('RoundEvent')



local function playGame()

    local timeAmount = 180

    local timerText = 'Remaining Time: '

    while timeAmount > 0 do

        timeEvent:FireAllClients(timeAmount, timerText)

        wait(1)

        timeAmount -= 1

    end

end



local function playIntermission()

    local intermission = 10

    local timerText = 'Intermission: '

    while intermission > 0 do

        timeEvent:FireAllClients(intermission, timerText)

        wait(1)

        intermission -= 1

    end

end



local function resetPlayers()

    for _, plr in pairs(game.Players:GetChildren()) do

        plr.Character.HumanoidRootPart.CFrame = CFrame.new(lobbyLocation)

        local CurrentMapFolder = game.Workspace.CurrentMap:GetChildren()

        for _, Map in ipairs(CurrentMapFolder) do

            if Map:IsA("Model") then

                Map:Destroy()

            end

        end

        local WeaponGiverFolder = game.Workspace.WeaponGivers:GetChildren()

        for _, Script in ipairs(WeaponGiverFolder) do

            if Script:IsA("Script") then

                Script.Enabled = false

            end

        end

    end 

end



local function teleportPlayers()

    for _, plr in pairs(game.Players:GetChildren()) do

        local RandomMap = math.random(1,1)

        if RandomMap == 1 then
            local OldSFOTHMap = game:GetService("ReplicatedStorage").Maps["Old SFOTH Map"]:Clone()
            OldSFOTHMap.Parent = game.Workspace
        end

        if RandomMap == 2 then
            local CubeSchool = game:GetService("ReplicatedStorage").Maps["Cube School"]:Clone()
            CubeSchool.Parent = game.Workspace
        end

        local WeaponGiverFolder = game.Workspace.WeaponGivers:GetChildren()

        for _, Script in ipairs(WeaponGiverFolder) do

            if Script:IsA("Script") then

                Script.Enabled = true

            end

        end

    end 

end



while true do

    resetPlayers()

    playIntermission()

    teleportPlayers()

    roundEvent:Fire()

    playGame()

end

Answer this question