Timer resetting Problem and Timer isn't working?

I’m stuck with the Timer situation.

There is a timer with 2 minutes and if you die, that timer resets. I just can’t do that!

That’s Number 1…

Number 2…

The problem is that there is not even an error and the code of the timer on the code block below doesn’t work!

--torture time
local rep = game:GetService("ReplicatedStorage")
local mapsfolder = game:GetService("Lighting"):WaitForChild("Maps")

local booleans = rep:WaitForChild("Booleans")
local variables = rep:WaitForChild("Variables")
local choice1 = variables:FindFirstChild("Choice1")
local choice2 = variables:FindFirstChild("Choice2")
local choice3 = variables:FindFirstChild("Choice3")
local winner = variables:FindFirstChild("Winner")
local Alive = workspace.Values.Alive
local TimerEnabled = workspace.Values.TimerEnabled
local timer = 121 --in seconds 121

while true do
while true do
    local maps = mapsfolder:GetChildren()
    choice1.Value = maps[math.random(1,#maps)]
    table.remove(maps,table.find(maps,choice1.Value))
    choice2.Value = maps[math.random(1,#maps)]
    table.remove(maps,table.find(maps,choice2.Value))
    choice3.Value = maps[math.random(1,#maps)]
    table.remove(maps,table.find(maps,choice3.Value))
    wait(1)
    booleans:FindFirstChild("VotingSession").Value = true
    wait(10)
    booleans:FindFirstChild("RevealVotes").Value = true
    wait(5)
    booleans:FindFirstChild("VotingSession").Value = false
    booleans:FindFirstChild("RevealVotes").Value = false
    local chosenmap = winner.Value

    if not winner.Value then
        print("Something went wrong!")
        break
    end
    local map = chosenmap.Value
    local clonemap = map:Clone()

    print("Getting map...")
    wait(1)
    print("Getting map spawn...")
    if clonemap.Spawn then
        print("Success!")
    else
        print("Task failed successfully")
        wait()
        print("Restarting...")
        clonemap:Destroy()
        break
    end
        clonemap.Parent = workspace
        clonemap.MusicZone.Stepped.Disabled = true

    print("Getting players...")
        local players = game:GetService("Players"):GetPlayers()

        for x, player in pairs(players) do
        local char = player.Character
        if not char then
            print(player.Name.." has no character!")
        else
            local humanoidrootpart = char.HumanoidRootPart
            if not humanoidrootpart then
                print(player.Name.." has no HumanoidRootPart!")
                else
                wait(1)
                    humanoidrootpart.CFrame = clonemap.Spawn.CFrame + Vector3.new(0,3,0)
                    player.InGame.Value = true
                    workspace.Values.Alive.Value += 1
                    TimerEnabled.Value = true
                end
        end
        wait()
        end

        clonemap.MusicZone.Stepped.Disabled = true

        wait(12)

        clonemap.MusicZone.Stepped.Disabled = false

        --Help me!

        local Start = clonemap.Start

        Start.Touched:Connect(function(hit, player)
            if hit.Start:FindFirstChild("Humanoid") then
                local char = player.Character
                local humanoid = char.Humanoid
                if humanoid.Health <= 0 then
                    Alive.Value -= 1
                end
            end
        end)

        Alive:GetPropertyChangedSignal("Value"):Connect(function()
            if Alive.Value ~= 0 then
                print("Game is going on...")
            else
                clonemap:Destroy()
            end
        end)

        TimerEnabled:GetPropertyChangedSignal("Value"):Connect(function()
            if TimerEnabled.Value == true then
                for i = timer,0,-1 do
                    print(i)
                    wait(1)
                end
            else
                clonemap:Destroy()
            end
        end)

        --Help me!

    for x, player in pairs(players) do
        local char = player.Character
        if not char then
            print(player.Name.." has no character!")
        else
            local humanoidrootpart = char.HumanoidRootPart
            if not humanoidrootpart then
                print(player.Name.." has no HumanoidRootPart!")
            else
                humanoidrootpart.CFrame = workspace.Lobby.SpawnLocation.CFrame + Vector3.new(0,3,0)
            end
        end
        wait()
    end
    clonemap:Destroy()
end
end

Please try to solve the case between the Help Mes!

Thank you!

Hello. You have two while loops

Maybe get rid of one of them for your script to work (also get rid of the extra end at the bottom)

Sorry, that’d break the script…

Because im making a round game and its just going to repeat and I need 2 while true do loops

One loop is needed. For some you would even need a loop. Trust me, that’s why ur the script isn’t erroring or printing

Oh ok ill check then! Im checking…

Where? Also that didn’t work… Bruh

Sorry about that. You might not need a wait. Idk, if there is something in the output that says exhaustion or something then you will need a wait at the start or end of the loop

No error but warnings about different stuff

Maybe changing the rep name for replicated storage might help, change it to RS or Replicatedstorage or something

Sorry I took long to respond :sweat_smile: my phone ran out of battery and I had to go to bed

What’s the difference though? I don’t see any difference!

Nvm (Just checked it, does nothing) Also add prints to debug the script

     TimerEnabled:GetPropertyChangedSignal("Value"):Connect(function()
            if TimerEnabled.Value == true then
                for i = timer,0,-1 do
                    print(i)
                    wait(1)
                end

Are you sure it’s not supposed to be:

     TimerEnabled:GetPropertyChangedSignal("Value"):Connect(function()
            if TimerEnabled.Value == true then
                for i = timer,-1 do
                    print(i)
                    wait(1)
                end
1 Like

Pretty sure that the winner value is an ObjectValue. (Line 30)
Delete this

local map = chosenmap.Value

and clone your choosen map

That’d also break the code… lol

Hm lemme see! Ima check rn eeeeee

Nope, it doesn’t work… This is getting ridiculous.

1 Like

This is just Winner.Value.Value.
change the map to Winner.Value or to choosen map

Hey I think that i fixed ur buggy mess :joy:
I pretty much changed the script but you can edit it to ur likings.

Code
local timer = 30 --in seconds 121
local timerspeed = 1 --timer speed

local players = game:GetService("Players"):GetPlayers()

local rep = game:GetService("ReplicatedStorage")
local mapsfolder = game:GetService("Lighting"):WaitForChild("Maps")

local booleans = rep:WaitForChild("Booleans")
local variables = rep:WaitForChild("Variables")
local choice1 = variables:FindFirstChild("Choice1")
local choice2 = variables:FindFirstChild("Choice2")
local choice3 = variables:FindFirstChild("Choice3")
local winner = variables:FindFirstChild("Winner")

local Alive = workspace.Values.Alive
local TimerEnabled = workspace.Values.TimerEnabled

local mapsFolder = mapsfolder:GetChildren()
local chosenmap = winner.Value

local maps = {}
local solo = false
local map

local function start ()
	for i,v in pairs(workspace.CurrentMap:GetChildren()) do
		if v.ClassName == "Model" then
			v:Destroy()
		end
	end
	workspace.Values.Alive.Value = 0
	TimerEnabled.Value = false
	print("Starting...")
	choice1.Value = maps[math.random(1,#mapsFolder)]
	table.remove(maps,table.find(maps,choice1.Value))
	choice2.Value = maps[math.random(1,#mapsFolder)]
	table.remove(maps,table.find(maps,choice2.Value))
	choice3.Value = maps[math.random(1,#mapsFolder)]
	table.remove(maps,table.find(maps,choice3.Value))
	wait(1)
	booleans:FindFirstChild("VotingSession").Value = true
	wait(10)
	booleans:FindFirstChild("RevealVotes").Value = true
	wait(5)
	booleans:FindFirstChild("VotingSession").Value = false
	booleans:FindFirstChild("RevealVotes").Value = false

	if not winner.Value then
		print("Something went wrong!")
	end

	local clonemap = chosenmap:Clone()
	map = clonemap

	print("Getting map...")

	if clonemap.Spawn then
		print("Success!")
	else
		print("Task failed successfully")
		clonemap:Destroy()
	end

	clonemap.Parent = workspace.CurrentMap

	for i, player in pairs(game:GetService("Players"):GetPlayers()) do
		local char = player.Character
		if char then
			local humanoidrootpart = char:FindFirstChild("HumanoidRootPart")
			print("TP")
			char:MoveTo(map.Spawn.Position + Vector3.new(0,3,0))
			--humanoidrootpart.Position = map.Spawn.Position + Vector3.new(0,3,0)
			player.InGame.Value = true
			Alive.Value += 1
			TimerEnabled.Value = true
		end
		wait()
	end

	if Alive.Value < 2 then
		if not solo then
			print("Two or more players needed to start")
			for i, player in pairs(game:GetService("Players"):GetPlayers()) do
				local char = player.Character
				if char then
					print("Game Over")
					char:MoveTo(workspace.Lobby.SpawnLocation.Position + Vector3.new(0,100,0))
					workspace.Values.Alive.Value = 0
					TimerEnabled.Value = false
				end
				wait()
			end
			start()
		end
	end

	if timer ~= 30 then
		timer = 35
	end
	
	print("Starting Game in 3")
	wait(1)
	print("Starting Game in 2")
	wait(1)
	print("Starting Game in 1")
	wait(1)
end

start()

while true do
	wait(timerspeed)
	if timer > 0 then
		timer -= 1

		print(timer)
		local Start = map:FindFirstChild("Start")

		Start.Touched:Connect(function(hit)
			if hit.Parent:FindFirstChild("Humanoid") then
				local playerz = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
				local char = hit.Parent
				local humanoid = char.Humanoid
				if humanoid.Health > 0 then
					humanoid.Health = 0
					workspace.Values.Alive.Value -= 1
					playerz.InGame.Value = false
				end
			end
		end)

		if Alive.Value == 1 then
			if not solo then
				for i, player in pairs(game:GetService("Players"):GetPlayers()) do
					local char = player.Character
					if char then
						local humanoidrootpart = char:FindFirstChild("HumanoidRootPart")
						print("Game Over")
						char:MoveTo(workspace.Lobby.SpawnLocation.Position + Vector3.new(0,3,0))
						--humanoidrootpart.Position = workspace.Lobby.SpawnLocation.Position + Vector3.new(0,3,0)
						if player.InGame.Value == true then
							player.InGame.Value = false
							print("Winner is ".. player.Name)
						else
							print("Looser is ".. player.Name)
							player.InGame.Value = false
						end
						workspace.Values.Alive.Value = 0
						TimerEnabled.Value = false
					end
					wait()
				end
				wait(2)
				for i,v in pairs(workspace.CurrentMap:GetChildren()) do
					if v.ClassName == "Model" then
						v:Destroy()
					end
				end
				start()
			end
		end


	else
		for i, player in pairs(game:GetService("Players"):GetPlayers()) do
			print("Time Is UP")
			local char = player.Character
			if char then
				local humanoidrootpart = char:FindFirstChild("HumanoidRootPart")
				char:MoveTo(workspace.Lobby.SpawnLocation.Position + Vector3.new(0,3,0))
				--humanoidrootpart.Position = workspace.Lobby.SpawnLocation.Position + Vector3.new(0,3,0)
				if player.InGame.Value == true then
					player.InGame.Value = false
					print(player.Name.. " Won")
				else
					player.InGame.Value = false
					print(player.Name.. " Lost")
				end
				workspace.Values.Alive.Value = 0
				TimerEnabled.Value = false
			end
			wait()
		end
		wait(2)
		for i,v in pairs(workspace.CurrentMap:GetChildren()) do
			if v.ClassName == "Model" then
				v:Destroy()
			end
		end
		start()
	end
end

I also added some other features if you like. You can simply delete them if you dont them. Sorry that the script is long

Here is a video of how I think you want this system to work
Video Link

Yo man, I appreciate it. I’ma check if it works rn!