How i make a countimer when i press a button(part)?

Hello Im trying make a timer when u press a button(part button) and it puts a timer gui that it counts to 0 example 20 to 0.

  • What i wanna do? : Make a test for a school project in one hour cause i have some scripts made but i still need help.

Example (More Detailed) :

  • Here is what im trying to do when you press button(part) it appears a time gui to 20 to 0
    and when it finish it appears time finished in gui.

Thx For Reading I Hope See Some Answers! :slight_smile:

You could create a ClickDetector object inside the Part, then detect when that Part is clicked via the MouseClick Event in the ClickDetector

If you’ve already gotten your Timer Gui set up, all you’d just need to do is reference it (The nice thing about the MouseClick Event is that it has the Player as the first parameter, so you can just reference its PlayerGui easily)

After checking for the TimerGui, you can create a loop every second, which would slowly count down from the starting count (20), to the end count (0) while at the same time, changing the Timer’s Text:

local Part = script.Parent --This is where you would reference the Part
local ClickDetector = Part:WaitForChild("ClickDetector") --Checking to make sure that there's a ClickDetector inside the Part
local StartCountdown = 20
local EndCountdown = 0

local function StartCountdown(Player)
    local PlayerGui = Player.PlayerGui
    local TimerGui = PlayerGui:WaitForChild("TimerGui") --This is to ensure that there is a Timer Gui in your PlayerGui

    for TimerStatus = StartCountdown, EndCountdown, -1 do
        TimerGui.TextCountdown.Text = TimerStatus
        wait(1)
    end

    TimerGui.TextCountdown.Text = "Timer Finished!"
end

ClickDetector.MouseClick:Connect(StartCountdown) --You'd need to Connect your Events in order for a function to properly work

I’d be more than happy to give you a place file example if you want, but here’s an example on what you could do :slightly_smiling_face: