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

Why Continues The Timer When There Is One Player Alive?

When the game starts there are two or more players. If there is one player alive the player should get credits and return to the lobby. But instead of that the timer continues and the player won't get any credits. Any solutions?

Here is the script



view source

01	local mapsinserverstorage = game:GetService('ServerStorage'):GetChildren()  -- Make sure that your maps are in serverstorage. If you have more than just maps in serverstorage, the script might actually choose that.
02	local chosenmap = mapsinserverstorage[math.random(1, #mapsinserverstorage)]
03	chosenmap:Clone().Parent = mapstorage
04	status.Value = "Loading Map.."
05	wait(3)
06	local spawns = chosenmap:WaitForChild('Spawns'):GetChildren()
07	for _, player in pairs (game.Players:GetPlayers()) do
08	    if player and #spawns > 0 then
09	        local torso = player.Character:WaitForChild('HumanoidRootPart')
10	        local allspawns = math.random(1, #spawns)
11	        local randomspawn = spawns[allspawns]
12	        if randomspawn and torso then
13	            table.remove(spawns, allspawns)
14	            torso.CFrame = CFrame.new(randomspawn.Position + Vector3.new(0,2,0))
15	 
16	            local primary = game.ReplicatedStorage.Handgun -- CHANGE THIS TO WHATEVER ITEM YOU WANT TO GIVE THEM WHEN THEY ARE TELEPORTED. MAKE SURE IT IS IN REPLICATED STORAGE.
17	            local newprimary = primary:Clone()
18	            newprimary.Parent = player.Backpack
19	 
20	        end
21	    end
22	end
23	status.Value = "Be The Last Standing!"
24	if status.Value then
25	    game.Workspace.Sound:Stop()
26	end
27	wait(4)
28	for i = 196,0,-1 do -- You can adjust the #196 to how long you want the round to last.
29	    if i == 0 then
30	        status.Value = "Time is up!"
31	        wait(3)
32	        break
33	    end
34	    wait(1)
35	    if #_G.gameplayers == 1 then
36	        for i, v in pairs(_G.gameplayers) do
37	            if v ~= nil then
38	                status.Value = v.." Won The Game!"
39	                game.Players[v].leaderstats.Cash.Value = game.Players[v].leaderstats.Cash.Value + 15 -- The #15 will be how much credit or cash is awarded to the player if there was only one player teleported.
40	                break
41	            end
42	 
43	        end
44	        break
45	    else
46	        status.Value = i.."..Seconds Remaining!"
47	    end
48	end
49	    for i, player in ipairs(game.Players:GetPlayers()) do
50	    if player.Character then
51	        local hum = player.Character:FindFirstChild('Humanoid')
52	        if hum then
53	            hum.Health = 0
54	        end
55	    end
56	end
57	mapstorage:ClearAllChildren()
58	 
59	wait(5)
60	end

1 comment

0

Did you get this script from AlvinBlox? I remember watching some of his tutorials and this script is REALLY similar to one of his scripts. It might not be working because the script requires other separate scripts to handle the player tables. Did you set up the separate scripts?

1 answer

Create an IntValue in Workspace, call it gametime, and the script should work for you now.

local gametime = workspace.gametime
----------
local mapsinserverstorage = game:GetService('ServerStorage'):GetChildren()  -- Make sure that your maps are in serverstorage. If you have more than just maps in serverstorage, the script might actually choose that.
local chosenmap = mapsinserverstorage[math.random(1, #mapsinserverstorage)]
chosenmap:Clone().Parent = mapstorage
status.Value = "Loading Map.."
wait(3)
local spawns = chosenmap:WaitForChild('Spawns'):GetChildren()
	for _, player in pairs (game.Players:GetPlayers()) do
	if player and #spawns > 0 then
	local torso = player.Character:WaitForChild('HumanoidRootPart')
	local allspawns = math.random(1, #spawns)
	local randomspawn = spawns[allspawns]
	if randomspawn and torso then
	 table.remove(spawns, allspawns)
	 torso.CFrame = CFrame.new(randomspawn.Position + Vector3.new(0,2,0))
	
	local primary = game.ReplicatedStorage.Handgun -- CHANGE THIS TO WHATEVER ITEM YOU WANT TO GIVE THEM WHEN THEY ARE TELEPORTED. MAKE SURE IT IS IN REPLICATED STORAGE.
	 local newprimary = primary:Clone()
	  newprimary.Parent = player.Backpack
	
	     end
	    end
	  end
 	 status.Value = "Be The Last Standing!"
	wait(3)
	status.Value = ""
  if status.Value == "" then
     game.Workspace.Sound:Stop()
  end
  wait(4)
	gametime.Value = 196
	while true do
		if gametime.Value == 0 then
			gametime.Value = gametime.Value - 0
			wait(1)
		elseif gametime.Value == 1 then
			wait(1)
			gametime.Value = gametime.Value - 1
		elseif gametime.Value ~= 0 then
			gametime.Value = gametime.Value - 1
			wait(1)
		end
	end
	while gametime.Value ~= 0 do
		wait()
	end
  	 status.Value = "Time is up!"
      wait(3)
      if #_G.gameplayers == 1 then
          for i, v in pairs(_G.gameplayers) do
			gametime.Value = 0
              if v ~= nil then
                  status.Value = v.." Won The Game!"
                  game.Players[v].leaderstats.Cash.Value = game.Players[v].leaderstats.Cash.Value + 15 -- The #15 will be how much credit or cash is awarded to the player if there was only one player teleported.
              end
          end
      else
          status.Value = gametime.Value.." Seconds Remaining!"
      end
      for i, player in ipairs(game.Players:GetPlayers()) do
      if player.Character then
          local hum = player.Character:FindFirstChild('Humanoid')
          if hum then
              hum.Health = 0
          end
      end
  end
  mapstorage:ClearAllChildren()
  wait(5)

1 comment

0

Hi, thanks for your reply. It did not work :( I think ill need to rescript the script.

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