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

How do I change this script so that the clock doesn't reset after one player dies?

How do I change this script so that all players die at the same time, and the clock doesn't reset after One person dies?

local time = 2500 
for i = 1, 2500 do 
wait(1) 
time = time - 1 
script.Parent.Text = tostring(time) 
end 
script.Parent.Text = "game over"
script.Parent.Parent.Parent.Parent.Character.Humanoid.Health = 0 

2 comments

1

Placing important game logic on each and every client is a very bad idea - you will have to make the server handle it.

0

^ What he said.

1 answer

Put this in a Script inside Workspace.

local players = {} -- table for players

local time = 2500
for i = 1,2500 do
	wait(1)
	time = time - 1
end

game.Players.PlayerAdded:connect(function(p) -- when a player is added
	local gui = p.PlayerGui:WaitForChild("GuiName") -- finds the gui
	if gui then
		local text = gui.TextLabel -- finds the TextLabel
		if text then
			p.CharacterAdded:connect(function(char) -- when their character is added
				local human = char:WaitForChild("Humanoid") -- finds the humanoid
				human.Died:connect(function() -- when a player dies
					text.Text = "Game Over" -- changes text
				end)
			end)
			players:insert(p) -- puts the player in the table
		end
	end
end)

game.Players.PlayerRemoving:connect(function(p)
	table.remove(players,p) -- removes player from table, to avoid nil values
end

while true do -- repeats forever, can only have one infinite While loop in a script, only put these at the bottom of a script
	for _,v in pairs (players) do -- does this for every player
		local find = v.PlayerGui:FindFirstChild("GuiName")
		if find then
			local text = find.TextLabel
			if text then
				text.Text = tostring(time) -- changes text to time
			end
		end
	end
	wait()
end

1 comment

0

ServerScriptService is where server-sided scripts should be stored, not Workspace.

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