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

How to make my timer keep going after death?

Asked by 2 years ago

Hello, I am still having a little bit of trouble with my timer. I have a map changing system that changes the map of my game after 600 seconds, and my timer is going to be set to 600 seconds (10 minutes), but I've been trying to test play my game after putting the script of my timer into a gui, and whenever I die it completely resets my timer and I want the timer to keep going even after death. Here's the code to my gui:

-- Instances:

local ScreenGui = Instance.new("ScreenGui")
local TimerNumbers = Instance.new("TextLabel")
local Frame = Instance.new("Frame")
local TextButton = Instance.new("TextButton")

--Properties:

ScreenGui.Parent = game.Players.LocalPlayer:WaitForChild("PlayerGui")
ScreenGui.ZIndexBehavior = Enum.ZIndexBehavior.Sibling
ScreenGui.ResetOnSpawn = false

TimerNumbers.Name = "TimerNumbers"
TimerNumbers.Parent = ScreenGui
TimerNumbers.AnchorPoint = Vector2.new(0.5, 0.5)
TimerNumbers.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
TimerNumbers.BackgroundTransparency = 1.000
TimerNumbers.BorderSizePixel = 0
TimerNumbers.Position = UDim2.new(0.5, 0, 0.0500000007, 0)
TimerNumbers.Size = UDim2.new(0.5, 0, 0, 50)
TimerNumbers.Visible = false
TimerNumbers.Font = Enum.Font.Cartoon
TimerNumbers.Text = "00:00"
TimerNumbers.TextColor3 = Color3.fromRGB(255, 255, 255)
TimerNumbers.TextScaled = true
TimerNumbers.TextSize = 14.000
TimerNumbers.TextWrapped = true
TimerNumbers.Visible = true

Frame.Parent = ScreenGui
Frame.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
Frame.Position = UDim2.new(0.360549718, 0, 0.370679379, 0)
Frame.Size = UDim2.new(0, 344, 0, 216)
Frame.Visible = true

TextButton.Parent = Frame
TextButton.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
TextButton.Position = UDim2.new(0.209302321, 0, 0.333333343, 0)
TextButton.Size = UDim2.new(0, 200, 0, 50)
TextButton.Font = Enum.Font.SourceSans
TextButton.TextColor3 = Color3.fromRGB(0, 0, 0)
TextButton.TextSize = 14.000
TextButton.MouseButton1Click:connect(function()
    Frame.Visible = false
end)

-- Scripts:

local function VLHW_fake_script() -- TimerNumbers.Script 
    local script = Instance.new('Script', TimerNumbers)

    local timer = script.Parent
    local minutes = 0
    local seconds = 5

    repeat
        if seconds <= 0 then
            minutes = minutes - 1
            seconds = 59
        else
            seconds = seconds - 1
        end
        if seconds < 10 then
            timer.Text = tostring(minutes)..":0"..tostring(seconds)
        else 
            timer.Text = tostring(minutes)..":"..tostring(seconds)
        end
        wait(1)
    until minutes <= 0 and seconds <= 0

    for i,v in ipairs(game.Players:GetPlayers()) do
        local character = v.Character
        local humanoid

        if character then
            humanoid = character:FindFirstChildOfClass("Humanoid")
        end

        if humanoid and humanoid.Health > 0 then
            humanoid.Health = 0
        end

        Frame.Visible = true
        v.TeamColor = BrickColor.new("Really red")
    end
end
coroutine.wrap(VLHW_fake_script)()

Where it says --Scripts is where my timer script is located. The rest is just the lua to my gui, and whenever I set ResetOnSpawn to true, my timer resets after every death which isn't what I want, but when I set it to false, it just completely stops after it runs out of time. I don't know how to make it just continuously run after 10 minutes. Any ideas?

0
create a single ServerScriptService.Script which will swap the maps and send remote event signals to all clients, these clients will have LocalScript which will start the timer every time an even is sent. ResetOnSpawn as false is good. imKirda 4491 — 2y
0
in general, make sure you find the code that resets the timer in general, and also do what @imKirda has said. Antelear 185 — 2y
0
also there's a trick called string formatting (https://developer.roblox.com/en-us/articles/Format-String) that will make you rethink your whole existence, run this script (server or client) and see what i mean: https://gist.github.com/kirdaaa/468c1213a867a5c2a470610b60b79c3d imKirda 4491 — 2y
0
okay so once I put it into serverscriptservice how could I make it so that it opens a GUI after the timer is finished? AROBLOXUSER12344 24 — 2y

1 answer

Log in to vote
0
Answered by 2 years ago

It is because you are making Instance.new("ScreenGui") . You have to make GUI in StarterGui by yourself, not script. Else it will Create new GUI and of course it will reset it. also keep ResetOnSpawn = false

Ad

Answer this question