Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

The round script resetting when a new player joins?

Hello! I'm trying to make rounds with the following script:

game.Players.PlayerAdded:Connect(function(plr)
	wait(7.5)
	local Player = game.Players:FindFirstChild(plr.Name)
	local GUI = Player.PlayerGui.RoundsGUI
	local function toround()
		GUI.Status.Text = "Status: In round"
		GUI.Sixty.Disabled = true
		GUI.ThreeSixty.Disabled = false
		game.Workspace.Rift.Rift.Rift.TimePosition = 9.5
		game.Workspace.Rift.Rift.Rift:Play()
		game.Workspace.Rift.Rift.Transparency = 0
		Player.Character.HumanoidRootPart.CFrame = game.Workspace.Rift.Rift.CFrame
		wait(5)
		game.Workspace.Rift.Rift.Transparency = 1
	end
	local function tolobby()
		if Player.Character:FindFirstChild("[NON VIP] Laser blaster") then
			Player.Character["[NON VIP] Laser blaster"]:Destroy()
		end
		if Player.Character:FindFirstChild("[DROP] Laser blaster") then
			Player.Character["[DROP] Laser blaster"]:Destroy()
		end
		if Player.Character:FindFirstChild("[VIP] Laser blaster") then
			Player.Character["[VIP] Laser blaster"]:Destroy()
		end
		if Player.Character:FindFirstChild("[MYTHIC] Laser blaster") then
			Player.Character["[MYTHIC] Laser blaster"]:Destroy()
		end
		if Player.Character:FindFirstChild("[NON VIP] Sword") then
			Player.Character["[NON VIP] Sword"]:Destroy()
		end
		if Player.Character:FindFirstChild("[DROP] Sword") then
			Player.Character["[DROP] Sword"]:Destroy()
		end
		if Player.Character:FindFirstChild("[VIP] Sword") then
			Player.Character["[VIP] Sword"]:Destroy()
		end
		if Player.Character:FindFirstChild("[MYTHIC] Sword") then
			Player.Character["[MYTHIC] Sword"]:Destroy()
		end
		if Player.Character:FindFirstChild("[NON VIP] Med kit") then
			Player.Character["[NON VIP] Med kit"]:Destroy()
		end
		if Player.Character:FindFirstChild("[DROP] Med kit") then
			Player.Character["[DROP] Med kit"]:Destroy()
		end
		if Player.Character:FindFirstChild("[VIP] Med kit") then
			Player.Character["[VIP] Med kit"]:Destroy()
		end
		if Player.Character:FindFirstChild("[NON VIP] Parachute") then
			Player.Character["[NON VIP] Parachute"]:Destroy()
		end
		Player.Character.MedKits.Disabled = true
		GUI.RoundMode.Text = "Gamemode: "
		GUI.Status.Text = "Status: In lobby"
		GUI.ThreeSixty.Disabled = true
		GUI.Sixty.Disabled = false
		Player.Backpack:ClearAllChildren()
		Player.Character.Humanoid.Health = 100
		game.Workspace.Lobby.LobbyRift.Rift.Rift.TimePosition = 9.5
		game.Workspace.Lobby.LobbyRift.Rift.Rift:Play()
		game.Workspace.Lobby.LobbyRift.Rift.Transparency = 0
		Player.Character.HumanoidRootPart.CFrame = game.Workspace.Lobby.LobbyRift.Rift.CFrame
		wait(5)
		game.Workspace.Lobby.LobbyRift.Rift.Transparency = 1
		game.Workspace.Drop1.Drop.ReEnable.Disabled = true
		game.Workspace.Drop1.PositionRift.Transparency = 1
		game.Workspace.Drop1.Laser.Transparency = 1
		game.Workspace.Drop1.Drop.Transparency = 1
		game.Workspace.Drop1.Drop.System.Disabled = true
		game.Workspace.Drop1.Drop.Reset.Disabled = true
		game.Workspace.Drop1.Drop.ReEnable.Disabled = true
		game.Workspace.Drop1.Drop.BillboardGui.Enabled = false
		game.Workspace.Drop2.Drop.ReEnable.Disabled = true --New drop
		game.Workspace.Drop2.PositionRift.Transparency = 1
		game.Workspace.Drop2.Laser.Transparency = 1
		game.Workspace.Drop2.Drop.Transparency = 1
		game.Workspace.Drop2.Drop.System.Disabled = true
		game.Workspace.Drop2.Drop.Reset.Disabled = true
		game.Workspace.Drop2.Drop.ReEnable.Disabled = true
		game.Workspace.Drop2.Drop.BillboardGui.Enabled = false
		game.Workspace.Drop3.Drop.ReEnable.Disabled = true --New drop
		game.Workspace.Drop3.PositionRift.Transparency = 1
		game.Workspace.Drop3.Laser.Transparency = 1
		game.Workspace.Drop3.Drop.Transparency = 1
		game.Workspace.Drop3.Drop.System.Disabled = true
		game.Workspace.Drop3.Drop.Reset.Disabled = true
		game.Workspace.Drop3.Drop.ReEnable.Disabled = true
		game.Workspace.Drop3.Drop.BillboardGui.Enabled = false
		game.Workspace.Drop4.Drop.ReEnable.Disabled = true --New drop
		game.Workspace.Drop4.PositionRift.Transparency = 1
		game.Workspace.Drop4.Laser.Transparency = 1
		game.Workspace.Drop4.Drop.Transparency = 1
		game.Workspace.Drop4.Drop.System.Disabled = true
		game.Workspace.Drop4.Drop.Reset.Disabled = true
		game.Workspace.Drop4.Drop.ReEnable.Disabled = true
		game.Workspace.Drop4.Drop.BillboardGui.Enabled = false
		game.Workspace.Drop5.Drop.ReEnable.Disabled = true --New drop
		game.Workspace.Drop5.PositionRift.Transparency = 1
		game.Workspace.Drop5.Laser.Transparency = 1
		game.Workspace.Drop5.Drop.Transparency = 1
		game.Workspace.Drop5.Drop.System.Disabled = true
		game.Workspace.Drop5.Drop.Reset.Disabled = true
		game.Workspace.Drop5.Drop.ReEnable.Disabled = true
		game.Workspace.Drop5.Drop.BillboardGui.Enabled = false
		game.Workspace.Drop6.Drop.ReEnable.Disabled = true --New drop
		game.Workspace.Drop6.PositionRift.Transparency = 1
		game.Workspace.Drop6.Laser.Transparency = 1
		game.Workspace.Drop6.Drop.Transparency = 1
		game.Workspace.Drop6.Drop.System.Disabled = true
		game.Workspace.Drop6.Drop.Reset.Disabled = true
		game.Workspace.Drop6.Drop.ReEnable.Disabled = true
		game.Workspace.Drop6.Drop.BillboardGui.Enabled = false
		game.Workspace.Drop7.Drop.ReEnable.Disabled = true --New drop
		game.Workspace.Drop7.PositionRift.Transparency = 1
		game.Workspace.Drop7.Laser.Transparency = 1
		game.Workspace.Drop7.Drop.Transparency = 1
		game.Workspace.Drop7.Drop.System.Disabled = true
		game.Workspace.Drop7.Drop.Reset.Disabled = true
		game.Workspace.Drop7.Drop.ReEnable.Disabled = true
		game.Workspace.Drop7.Drop.BillboardGui.Enabled = false
		game.Workspace.Drop8.Drop.ReEnable.Disabled = true --New drop
		game.Workspace.Drop8.PositionRift.Transparency = 1
		game.Workspace.Drop8.Laser.Transparency = 1
		game.Workspace.Drop8.Drop.Transparency = 1
		game.Workspace.Drop8.Drop.System.Disabled = true
		game.Workspace.Drop8.Drop.Reset.Disabled = true
		game.Workspace.Drop8.Drop.ReEnable.Disabled = true
		game.Workspace.Drop8.Drop.BillboardGui.Enabled = false
		game.Workspace.Drop9.Drop.ReEnable.Disabled = true --New drop
		game.Workspace.Drop9.PositionRift.Transparency = 1
		game.Workspace.Drop9.Laser.Transparency = 1
		game.Workspace.Drop9.Drop.Transparency = 1
		game.Workspace.Drop9.Drop.System.Disabled = true
		game.Workspace.Drop9.Drop.Reset.Disabled = true
		game.Workspace.Drop9.Drop.ReEnable.Disabled = true
		game.Workspace.Drop9.Drop.BillboardGui.Enabled = false
	end
	local function startdrop()
		game.Workspace.Drop1.Drop.ReEnable.Disabled = false
	end
	local function startdropmode()
		game.Workspace.Drop2.Drop.ReEnable.Disabled = false
		game.Workspace.Drop3.Drop.ReEnable.Disabled = false
		game.Workspace.Drop4.Drop.ReEnable.Disabled = false
		game.Workspace.Drop5.Drop.ReEnable.Disabled = false
		game.Workspace.Drop6.Drop.ReEnable.Disabled = false
		game.Workspace.Drop7.Drop.ReEnable.Disabled = false
		game.Workspace.Drop8.Drop.ReEnable.Disabled = false
		game.Workspace.Drop9.Drop.ReEnable.Disabled = false
	end
	local Value = script.Value.Value
	local Gamemodes = game.ServerStorage.Gamemodes
	--Start cycle
	tolobby()
	Value = math.random(1,1)
	if Value == 1 then
		print(Value)
		wait(10)
		GUI.RoundMode.Text = "Gamemode: Only MYTHIC weapons"
		Gamemodes.OnlyMythicWeapons["[NON VIP] Parachute"]:Clone().Parent = Player.Backpack
		Gamemodes.OnlyMythicWeapons["[NON VIP] Med kit"]:Clone().Parent = Player.Backpack
		Gamemodes.OnlyMythicWeapons["[MYTHIC] Laser blaster"]:Clone().Parent = Player.Backpack
		Gamemodes.OnlyMythicWeapons["[MYTHIC] Sword"]:Clone().Parent = Player.Backpack
		toround()
		game.ServerStorage.Zombies:Clone().Parent = game.Workspace
		wait(10)
		game.Workspace.Zombies:Destroy()
		tolobby()
		Value = 0
		script.Reset.Disabled = false
	end
	if Value == 2 then
		print(Value)
		wait(60)
		GUI.RoundMode.Text = "Gamemode: Drops only"
		Gamemodes.OnlyDropsMode["[NON VIP] Parachute"]:Clone().Parent = Player.Backpack
		startdropmode()
		toround()
		wait(60)
		game.ServerStorage.Zombies:Clone().Parent = game.Workspace
		wait(300)
		game.Workspace.Zombies:Destroy()
		tolobby()
		Value = 0
		script.Reset.Disabled = false
	end
end)

The matter is that when a new player joins, the script is individual and the scripts are working like two. Is there any way to get the player, but avoiding to the script to "dupplicate" when a new player joins? Thnak you.

1 answer

Hello. You can use :Disconnect() to disconnect the PlayerAdded event when a player joins. Try this:

local onPlayerAddedConnection

onPlayerAddedConnection = game.Players.PlayerAdded:Connect(function(plr)
	onPlayerAddedConnection:Disconnect()
    wait(7.5)
    local Player = game.Players:FindFirstChild(plr.Name)
    local GUI = Player.PlayerGui.RoundsGUI
    local function toround()
        GUI.Status.Text = "Status: In round"
        GUI.Sixty.Disabled = true
        GUI.ThreeSixty.Disabled = false
        game.Workspace.Rift.Rift.Rift.TimePosition = 9.5
        game.Workspace.Rift.Rift.Rift:Play()
        game.Workspace.Rift.Rift.Transparency = 0
        Player.Character.HumanoidRootPart.CFrame = game.Workspace.Rift.Rift.CFrame
        wait(5)
        game.Workspace.Rift.Rift.Transparency = 1
    end
    local function tolobby()
        if Player.Character:FindFirstChild("[NON VIP] Laser blaster") then
            Player.Character["[NON VIP] Laser blaster"]:Destroy()
        end
        if Player.Character:FindFirstChild("[DROP] Laser blaster") then
            Player.Character["[DROP] Laser blaster"]:Destroy()
        end
        if Player.Character:FindFirstChild("[VIP] Laser blaster") then
            Player.Character["[VIP] Laser blaster"]:Destroy()
        end
        if Player.Character:FindFirstChild("[MYTHIC] Laser blaster") then
            Player.Character["[MYTHIC] Laser blaster"]:Destroy()
        end
        if Player.Character:FindFirstChild("[NON VIP] Sword") then
            Player.Character["[NON VIP] Sword"]:Destroy()
        end
        if Player.Character:FindFirstChild("[DROP] Sword") then
            Player.Character["[DROP] Sword"]:Destroy()
        end
        if Player.Character:FindFirstChild("[VIP] Sword") then
            Player.Character["[VIP] Sword"]:Destroy()
        end
        if Player.Character:FindFirstChild("[MYTHIC] Sword") then
            Player.Character["[MYTHIC] Sword"]:Destroy()
        end
        if Player.Character:FindFirstChild("[NON VIP] Med kit") then
            Player.Character["[NON VIP] Med kit"]:Destroy()
        end
        if Player.Character:FindFirstChild("[DROP] Med kit") then
            Player.Character["[DROP] Med kit"]:Destroy()
        end
        if Player.Character:FindFirstChild("[VIP] Med kit") then
            Player.Character["[VIP] Med kit"]:Destroy()
        end
        if Player.Character:FindFirstChild("[NON VIP] Parachute") then
            Player.Character["[NON VIP] Parachute"]:Destroy()
        end
        Player.Character.MedKits.Disabled = true
        GUI.RoundMode.Text = "Gamemode: "
        GUI.Status.Text = "Status: In lobby"
        GUI.ThreeSixty.Disabled = true
        GUI.Sixty.Disabled = false
        Player.Backpack:ClearAllChildren()
        Player.Character.Humanoid.Health = 100
        game.Workspace.Lobby.LobbyRift.Rift.Rift.TimePosition = 9.5
        game.Workspace.Lobby.LobbyRift.Rift.Rift:Play()
        game.Workspace.Lobby.LobbyRift.Rift.Transparency = 0
        Player.Character.HumanoidRootPart.CFrame = game.Workspace.Lobby.LobbyRift.Rift.CFrame
        wait(5)
        game.Workspace.Lobby.LobbyRift.Rift.Transparency = 1
        game.Workspace.Drop1.Drop.ReEnable.Disabled = true
        game.Workspace.Drop1.PositionRift.Transparency = 1
        game.Workspace.Drop1.Laser.Transparency = 1
        game.Workspace.Drop1.Drop.Transparency = 1
        game.Workspace.Drop1.Drop.System.Disabled = true
        game.Workspace.Drop1.Drop.Reset.Disabled = true
        game.Workspace.Drop1.Drop.ReEnable.Disabled = true
        game.Workspace.Drop1.Drop.BillboardGui.Enabled = false
        game.Workspace.Drop2.Drop.ReEnable.Disabled = true --New drop
        game.Workspace.Drop2.PositionRift.Transparency = 1
        game.Workspace.Drop2.Laser.Transparency = 1
        game.Workspace.Drop2.Drop.Transparency = 1
        game.Workspace.Drop2.Drop.System.Disabled = true
        game.Workspace.Drop2.Drop.Reset.Disabled = true
        game.Workspace.Drop2.Drop.ReEnable.Disabled = true
        game.Workspace.Drop2.Drop.BillboardGui.Enabled = false
        game.Workspace.Drop3.Drop.ReEnable.Disabled = true --New drop
        game.Workspace.Drop3.PositionRift.Transparency = 1
        game.Workspace.Drop3.Laser.Transparency = 1
        game.Workspace.Drop3.Drop.Transparency = 1
        game.Workspace.Drop3.Drop.System.Disabled = true
        game.Workspace.Drop3.Drop.Reset.Disabled = true
        game.Workspace.Drop3.Drop.ReEnable.Disabled = true
        game.Workspace.Drop3.Drop.BillboardGui.Enabled = false
        game.Workspace.Drop4.Drop.ReEnable.Disabled = true --New drop
        game.Workspace.Drop4.PositionRift.Transparency = 1
        game.Workspace.Drop4.Laser.Transparency = 1
        game.Workspace.Drop4.Drop.Transparency = 1
        game.Workspace.Drop4.Drop.System.Disabled = true
        game.Workspace.Drop4.Drop.Reset.Disabled = true
        game.Workspace.Drop4.Drop.ReEnable.Disabled = true
        game.Workspace.Drop4.Drop.BillboardGui.Enabled = false
        game.Workspace.Drop5.Drop.ReEnable.Disabled = true --New drop
        game.Workspace.Drop5.PositionRift.Transparency = 1
        game.Workspace.Drop5.Laser.Transparency = 1
        game.Workspace.Drop5.Drop.Transparency = 1
        game.Workspace.Drop5.Drop.System.Disabled = true
        game.Workspace.Drop5.Drop.Reset.Disabled = true
        game.Workspace.Drop5.Drop.ReEnable.Disabled = true
        game.Workspace.Drop5.Drop.BillboardGui.Enabled = false
        game.Workspace.Drop6.Drop.ReEnable.Disabled = true --New drop
        game.Workspace.Drop6.PositionRift.Transparency = 1
        game.Workspace.Drop6.Laser.Transparency = 1
        game.Workspace.Drop6.Drop.Transparency = 1
        game.Workspace.Drop6.Drop.System.Disabled = true
        game.Workspace.Drop6.Drop.Reset.Disabled = true
        game.Workspace.Drop6.Drop.ReEnable.Disabled = true
        game.Workspace.Drop6.Drop.BillboardGui.Enabled = false
        game.Workspace.Drop7.Drop.ReEnable.Disabled = true --New drop
        game.Workspace.Drop7.PositionRift.Transparency = 1
        game.Workspace.Drop7.Laser.Transparency = 1
        game.Workspace.Drop7.Drop.Transparency = 1
        game.Workspace.Drop7.Drop.System.Disabled = true
        game.Workspace.Drop7.Drop.Reset.Disabled = true
        game.Workspace.Drop7.Drop.ReEnable.Disabled = true
        game.Workspace.Drop7.Drop.BillboardGui.Enabled = false
        game.Workspace.Drop8.Drop.ReEnable.Disabled = true --New drop
        game.Workspace.Drop8.PositionRift.Transparency = 1
        game.Workspace.Drop8.Laser.Transparency = 1
        game.Workspace.Drop8.Drop.Transparency = 1
        game.Workspace.Drop8.Drop.System.Disabled = true
        game.Workspace.Drop8.Drop.Reset.Disabled = true
        game.Workspace.Drop8.Drop.ReEnable.Disabled = true
        game.Workspace.Drop8.Drop.BillboardGui.Enabled = false
        game.Workspace.Drop9.Drop.ReEnable.Disabled = true --New drop
        game.Workspace.Drop9.PositionRift.Transparency = 1
        game.Workspace.Drop9.Laser.Transparency = 1
        game.Workspace.Drop9.Drop.Transparency = 1
        game.Workspace.Drop9.Drop.System.Disabled = true
        game.Workspace.Drop9.Drop.Reset.Disabled = true
        game.Workspace.Drop9.Drop.ReEnable.Disabled = true
        game.Workspace.Drop9.Drop.BillboardGui.Enabled = false
    end
    local function startdrop()
        game.Workspace.Drop1.Drop.ReEnable.Disabled = false
    end
    local function startdropmode()
        game.Workspace.Drop2.Drop.ReEnable.Disabled = false
        game.Workspace.Drop3.Drop.ReEnable.Disabled = false
        game.Workspace.Drop4.Drop.ReEnable.Disabled = false
        game.Workspace.Drop5.Drop.ReEnable.Disabled = false
        game.Workspace.Drop6.Drop.ReEnable.Disabled = false
        game.Workspace.Drop7.Drop.ReEnable.Disabled = false
        game.Workspace.Drop8.Drop.ReEnable.Disabled = false
        game.Workspace.Drop9.Drop.ReEnable.Disabled = false
    end
    local Value = script.Value.Value
    local Gamemodes = game.ServerStorage.Gamemodes
    --Start cycle
    tolobby()
    Value = math.random(1,1)
    if Value == 1 then
        print(Value)
        wait(10)
        GUI.RoundMode.Text = "Gamemode: Only MYTHIC weapons"
        Gamemodes.OnlyMythicWeapons["[NON VIP] Parachute"]:Clone().Parent = Player.Backpack
        Gamemodes.OnlyMythicWeapons["[NON VIP] Med kit"]:Clone().Parent = Player.Backpack
        Gamemodes.OnlyMythicWeapons["[MYTHIC] Laser blaster"]:Clone().Parent = Player.Backpack
        Gamemodes.OnlyMythicWeapons["[MYTHIC] Sword"]:Clone().Parent = Player.Backpack
        toround()
        game.ServerStorage.Zombies:Clone().Parent = game.Workspace
        wait(10)
        game.Workspace.Zombies:Destroy()
        tolobby()
        Value = 0
        script.Reset.Disabled = false
    end
    if Value == 2 then
        print(Value)
        wait(60)
        GUI.RoundMode.Text = "Gamemode: Drops only"
        Gamemodes.OnlyDropsMode["[NON VIP] Parachute"]:Clone().Parent = Player.Backpack
        startdropmode()
        toround()
        wait(60)
        game.ServerStorage.Zombies:Clone().Parent = game.Workspace
        wait(300)
        game.Workspace.Zombies:Destroy()
        tolobby()
        Value = 0
        script.Reset.Disabled = false
    end
end)

Please accept and upvote this answer if it helped.

1 comment

0

It just works for the first player who joined. I need it to work for every player.

This discussion is preserved as it was. New answers, comments, and votes are closed.