Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 8 years ago

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 
1
Placing important game logic on each and every client is a very bad idea - you will have to make the server handle it. Marios2 360 — 8y
0
^ What he said. LetThereBeCode 360 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago

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
0
ServerScriptService is where server-sided scripts should be stored, not Workspace. 1waffle1 2908 — 8y
Ad

Answer this question