Before I put in the code, I would like to say what I've done and what the problems are. First of all, it seems as if the debouncer I used isn't working at all, causing some functions to repeat themselves. Second of all, it outputs an error which I'm currently unsure of how to deal with. I've also tried using print statements to find out the issue, but it only tells me that something is activating twice for some unknown reason. Current Output Output: Players being indexed into an array. Player1 Player2 Number Of Player1 Array objects: 2 Random Number: 1 Sniper chosen: Player1 Numbe Of Player1 Array objects: 1 Random Number: 1 Sniper chosen: Player2 true 17:53:26.211 - ServerScriptService.Script:7: bad argument #2 to 'random' (interval is empty)
Current Code:
local Players1 = {}
local Sniper = ""
local IntermissionGUI = game.ReplicatedStorage:WaitForChild("InfoValue")
local function RandomSniper()
local Random = math.random(1,#Players1)
Sniper = Players1[Random]
print("# Of Player1 Array objects: " .. #Players1)
print("Random Number: "..tostring(Random))
print("Sniper chosen: " .. tostring(Sniper))
table.remove(Players1, Random)
return true
end
local function CountDown()
local Sound = Instance.new("Sound",game.Workspace)
Sound.SoundId = "http://www.roblox.com/asset/?id=134641113"
for i = 10,0,-1 do
IntermissionGUI.Value = "Intermissio n: " .. tostring(i)
Sound:Play()
wait(1.5)
Sound:Stop()
end
Sound:Remove()
end
local function PlayerToNumber()
local Players = game.Players:GetPlayers()
print("Players being indexed into an array.")
for i, v in pairs(Players) do
table.insert(Players1,i,v.Name)
print(Players1[i])
end
return true
end
local function SniperToPosition()
print(RandomSniper())
local Sniper1 = game.Players:FindFirstChild(Sniper)
if RandomSniper() == true then
print("Sniper's Name during the teleportation: "..Sniper1.Name)
if Sniper1.Character.Torso ~= nil then
Sniper1.Character.Torso.CFrame = game.Workspace.SpawningPart.CFrame
print("Sniper Teleport Successful!")
local Gun = game.ServerStorage.Sniper:Clone()
Gun.Parent = Sniper1.Backpack
end
end
end
local function PlayersToPosition()
for _, v in pairs(Players1) do
if v ~= Sniper then
game.Players:FindFirstChild(v).Character.Torso.CFrame = game.Workspace.PlayerSpawningPart.CFrame + Vector3.new(0,2,math.random(-20,20))
print("Players being Teleported:" .. v)
wait(3)
end
end
end
local function RestartTheGame(Player)
local humanoid = Player.Parent:FindFirstChild("Humanoid")
if humanoid then
if game.Players:GetPlayerFromCharacter(Player.Parent) then
if game.Players:GetPlayerFromCharacter(Player.Parent).TeamColor == "Really Blue" then
if humanoid.Health > 0 then
if game.ReplicatedStorage.GameInProgress.Value then
for _, v in pairs(game.Players:GetChildren()) do
local character = v.Character
if character then
local torso = character.Torso
if torso then
torso.CFrame = game.Workspace.SpawningPart.CFrame + Vector3.new(math.random(-8, 8), 2, math.random(-8,8))
end
end end
end
end
if game.ReplicatedStorage.NumberOfPlayers.Value > 1 then
game.ReplicatedStorage.GameInProgress.Value = true
CountDown()
PlayerToNumber()
RandomSniper()
SniperToPosition()
PlayersToPosition()
end
end
end
end
end
game.Players.PlayerRemoving:Connect(function(LeavingPlayer)
local PlayerCount = game.ReplicatedStorage.NumberOfPlayers.Value
PlayerCount = PlayerCount - 1
for i,v in pairs(Players1) do
if v == LeavingPlayer.Name then
table.remove(Players1, i)
if #Players1 < 2 then
game.ReplicatedStorage.GameInProgress.Value = false
end
end
end
end)
game.Workspace.WinBlock.Touched:connect(RestartTheGame)
game.Players.PlayerAdded:connect(function(NewPlayer)
local PlayerCount = game.ReplicatedStorage.NumberOfPlayers.Value
PlayerCount = PlayerCount + 1
if game.Players.NumPlayers > 1 and game.ReplicatedStorage.GameInProgress.Value == false then
print("Game In Progress: " ..tostring(game.ReplicatedStorage.GameInProgress.Value))
game.ReplicatedStorage.GameInProgress.Value = true
print("Game In Progress: " ..tostring(game.ReplicatedStorage.GameInProgress.Value))
CountDown()
PlayerToNumber()
RandomSniper()
SniperToPosition()
PlayersToPosition()
end
NewPlayer.CharacterAdded:connect(function(Character)
Character:WaitForChild("Humanoid").Died:connect(function()
if game.ReplicatedStorage.GameInProgress.Value == true then
if #Players1 > 0 then
for i,v in pairs(Players1) do
if v == NewPlayer.Name then
table.remove(Players1,i)
if #Players1 < 0 then
game.ReplicatedStorage.GameInProgress.Value = false
RestartTheGame()
end
end
end
end
else
game.ReplicatedStorage.GameInProgress.Value = false
RestartTheGame()
end
end)
end)
end)

1 comment
Also, before anyone complains about the lack of indents in the output description, I was unable to add those, mainly due to the fact that when I ask a question, most of the formatting gets removed.