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

How can I fix Bad Argument #2 (interval empty)? It says the problem is on line 32. Please help.

Asked by 4 years ago
Edited 4 years ago
-- Services
local replicatedStorage = game:GetService("ReplicatedStorage")
local serverStorage = game:GetService("ServerStorage")

local status = replicatedStorage.Values.Status

local timer = replicatedStorage.Values.Timer

local playersLeft = replicatedStorage.Values.PlayersLeft

local hitbox = game.ServerStorage:WaitForChild("Hitbox")

-- Config
local playersToStart = 2

local contestants = {}

-- Functions
local function chooseSeeker(availablePlayers)
    return availablePlayers[math.random(1,#availablePlayers)]
end

local function teleportPlayers(availablePlayers,spawns)
    for _, plr in pairs(availablePlayers) do
        if plr.Character then

            local tag = Instance.new("BoolValue")
            tag.Name = "Playing"
            tag.Parent = plr

            if plr.Character:FindFirstChild("HumanoidRootPart") then
                plr.Character.HumanoidRootPart.CFrame = spawns[math.random(1,#spawns)].CFrame + Vector3.new(0,5,0)
            end
        end
    end
end

local function toMS(s)
    return ("i:i"):format(s/60%60, s%60)
end

local function addHitbox(player)

    if player then
        if player.Character then
            local character = player.Character
            local hitboxClone = hitbox:Clone()
            hitboxClone.CFrame = character.HumanoidRootPart.CFrame
            local weld = Instance.new("Weld")
            weld.Part1 = hitboxClone
            weld.Part0 = character.HumanoidRootPart
            weld.Parent = hitboxClone
            hitboxClone.Parent = character
            print("hitbox added for "..player.Name)

            local seekerTag = game.ServerStorage.SeekerTag:Clone()
            seekerTag.Parent = player.Character.Head

            return hitboxClone
        end
    end
end

local function removeHitbox(player)
    if player.Character then
        if player.Character:FindFirstChild("Hitbox") then
            player.Character.Hitbox:Destroy()
        end
        if player.Character.Head:FindFirstChild("SeekerTag") then
            player.Character.Head.SeekerTag:Destroy()
        end
    end
end

local function isContestant(plr)
    for _, contestant in pairs(contestants) do
        if contestants == plr then
            return true
        end
    end

    return false
end



local function kickOutContestant(plr)
    for i, contestant in pairs(contestants) do
        if contestant == plr then
            table.remove(contestants,i)
            warn("Booted "..contestant.Name.." from the table")
        end
    end
end

local Players = game:GetService("Players")

Players.PlayerRemoving:Connect(function(player)
    kickOutContestant(player)
end)

while wait(1) do

    contestants = {}

    repeat

        status.Value = playersToStart.." PLAYERS REQUIRED TO START ("..#game.Players:GetPlayers().."/"..playersToStart..")"

        wait(1)

    until #game.Players:GetPlayers() >= playersToStart

    for i = 20,0,-1 do
        status.Value = "NEXT ROUND STARTING IN "..i.." SECONDS"
        wait(1)
    end

    contestants = game.Players:GetPlayers()

    local seeker = chooseSeeker(contestants)

    status.Value = "THE SEEKER IS..."
    wait(1)
    status.Value = seeker.Name.."!"

    wait(3)

    local map = game.Workspace.RoomMap.RoomBaseplate

    kickOutContestant(seeker)

    teleportPlayers(contestants,map.Spawns:GetChildren())

    math.randomseed(tick())

    local hitbox = addHitbox(seeker)

    seekerHitboxConnection = hitbox.Touched:Connect(function(hit)
        local player = game.Players:GetPlayerFromCharacter(hit.Parent)
        if player then -- real player
            if isContestant(player) then
                print("Real contestant")
                kickOutContestant(player)
                if player:FindFirstChild("Playing") then
                    player:FindFirstChild("Playing"):Destroy()
                end
                if player.Character then
                    player.Character.HumanoidRootPart:Destroy()
                end
                print("Kicked")
            end
        end
    end)

    for i = 45,0,-1 do
        status.Value = "SECONDS TO HIDE"
        timer.Value = toMS(i)
        playersLeft.Value = #contestants
        wait(1)
    end

    teleportPlayers({seeker},map.SeekerSpawns:GetChildren())

    status.Value = "THE SEEKER IS COMING"

    if seeker.Character then
        seeker.Character.Humanoid.WalkSpeed = 25
    end

    wait(3)

    local outcome = nil

    for i = 300,0,-1 do
        status.Value = "UNTIL ROUND ENDS"
        timer.Value = toMS(i)
        playersLeft.Value = #contestants

        for i, v in pairs(contestants) do
            print(v.Name.." is a remaining contestant")
        end

        if #contestants == 0 then
            outcome = "SeekerWon"
            break
        end

        wait(1)
    end

    if outcome == "SeekerWon" then
        status.Value = seeker.Name.." WINS"
    else
        status.Value = "THE SEEKER HAS RUN OUT OF TIME! HIDERS WIN!"
    end

    removeHitbox(seeker)

    wait(3)

    status.Value = "ROUND ENDED"

    if seekerHitboxConnection then seekerHitboxConnection:Disconnect() print("Successfully disconnected") end

    wait(2)
end

1 answer

Log in to vote
0
Answered by
Shubu13 29
4 years ago

I think

 plr.Character.HumanoidRootPart.CFrame = CFrame.new(spawns[math.random(1,#spawns)].CFrame + Vector3.new(0,5,0))
0
No, it didn't work :( rayiwnI 0 — 4y
0
hmm Shubu13 29 — 4y
Ad

Answer this question