I seem to be encountering an issue with certain listeners not activation when they logically should. I've tested the functions which they connect to and they seem to work, but whenever I to connect them to a listener, it doesn't seem to work.
Players1 = {}
Sniper = ""
local IntermissionGUI = game.ReplicatedStorage:WaitForChild("InfoValue")
function RandomSniper()
local Random = math.random(0,game.Players.NumPlayers)
Sniper = Players1[Random]
print(Sniper)
table.remove(Players1, Random)
return true
end
function CountDown()
for i = 10,0,-1 do
IntermissionGUI.Value = "Intermission: " .. i
local Sound = Instance.new("Sound",game.Workspace)
Sound.SoundId = "http://www.roblox.com/asset/?id=134641113"
Sound:Play()
wait(1.5)
Sound:Remove()
end
end
function PlayerToNumber()
local Players = game.Players:GetChildren()
print("Activating")
for i,v in pairs(Players) do
table.insert(Players1,i,v.Name)
print(Players1[i])
end
return true
end
function SniperToPosition()
print(RandomSniper())
if RandomSniper() == true then
local Sniper1 = game.Players:FindFirstChild(Sniper)
print(Sniper1.Name)
Sniper1.Character.Torso.CFrame = game.Workspace.SpawningPart.CFrame
local Gun = game.ServerStorage.Sniper:Clone()
Gun.Parent = Sniper1.Backpack
end
end
function PlayersToPosition()
for _,v in pairs(Players1) do
if v ~= Sniper then
game.Players:FindFirstChild(v).Character.Torso.CFrame = game.Workspace.PlayerSpawningPart.CFrame + CFrame.new(0,2,math.random(-20,20))
wait(3)
end
end
end
function RestartTheGame(Player)
if Player.Parent.Humanoid ~= nil and Player.TeamColor == "Really blue" and Player.Parent.Humanoid.Health > 0 and game.ReplicatedStorage.GameInProgress.Value == true then
local Players = game.Players:GetChildren()
for _,v in pairs(Players) do
game.Players:FindFirstChild(v.Name).Character.Torso.CFrame = game.Workspace.SpawningPart.CFrame + CFrame.new(math.random(-8,8),2,math.random(-8,8))
end
if game.ReplicatedStorage.NumberOfPlayers.Value > 1 then
game.ReplicatedStorage.GameInProgress.Value = true
CountDown()
PlayerToNumber()
RandomSniper()
SniperToPosition()
PlayersToPosition()
end
end
end
game.Players.PlayerAdded:connect(function()
local PlayerCount = game.ReplicatedStorage.NumberOfPlayers.Value
PlayerCount = PlayerCount + 1
end)
game.Players.PlayerRemoving:connect(function()
local PlayerCount = game.ReplicatedStorage.NumberOfPlayers.Value
PlayerCount = PlayerCount - 1
end)
game.ReplicatedStorage.NumberOfPlayers.Changed:connect(function()
local Players = game.Players:GetChildren()
if #Players > 1 and game.ReplicatedStorage.GameInProgress.Value == false then
game.ReplicatedStorage.GameInProgress.Value = true
game.ReplicatedStorage.MoreThan2Players.Value = true
CountDown()
PlayerToNumber()
RandomSniper()
SniperToPosition()
PlayersToPosition()
else
game.ReplicatedStorage.MoreThan2Players.Value = false
end
end)
game.Workspace.WinBlock.Touched:connect(RestartTheGame)

3 comments
Also, the code is supposed to cause a countdown, which then is followed by a random player being chosen and teleported to a location. Also whenever a player enters and leaves, an integer value is either decreased or increased, which then tests whether 2 players are in the game at a time.
Use prints to see where it stops. It may be because the player has already been created when the listeners are defined, meaning that they need to be put somewhere they can run before the player gets added.
Deadly, there is an issue to doing that, it's fairly hard to use prints considering it involves players entering the game, which testing mode in studio doesn't detect. Originally, that's what I normally do when debugging, but in this case, I'm unable to do so. However, I do appreciate your concern.