My Event Script Seems To Not Be Working.. Any Help?

I have created an event script and it shows some text every few seconds. The only thing is the text won’t change.

local TARGET_TIME = 1587477900 -- 12:00 on 20 April 2020 BST
local RunService = game:GetService("RunService")

RunService.Heartbeat:Connect( function()
	local diffSeconds = TARGET_TIME - os.time()
	local countdown = os.date( '!*t', diffSeconds ) -- The first argument is important to say we're working in UTC so no offsets get applied

    -- here you would update a GUI or whatever it is you need to do
	script.Parent.Text = ( '\n%i Days\n %i Hours\n %i Minutes\n %i Seconds' ):format(countdown.yday - 1, countdown.hour, countdown.min, countdown.sec)

	if diffSeconds <= 0 then
		script.Parent.Text = "Are You Ready?"
		wait(3)
		script.Parent.Text = "The Winner Of The Roblox Development Building Competition Is..."
		wait(1)
		script.Parent.Text = "3"
		wait(1)
		script.Parent.Text = "2"
		wait(1)
		script.Parent.Text = "1"
		wait(3)
		script.Parent.Text = "IDONKNOWANYMORE12 - Congratulations!"
		wait(10)
		script.Parent.Text = "Creators:\nBuilder - Aiden_12114\nScripter - Aiden_12114"
		wait(12)
		script.Parent.Text = "Now You May Leave."
	else

	end
end)
1 Like

Are there any errors in the output?

No, there seems to not be. I have checked it 7 times :smiley:

Because you are running heartbeat, any text changes in that loop will just get overwritten in the next frame. If you want the text in that part to change, you either need to add a debounce, or not put it in a heartbeat event.

How can I fix this? (I Got This Script From A Helper)

Try this
EDIT: I put the debounce at the top as the countdown could still overwrite the text.

local TARGET_TIME = 1587477900 -- 12:00 on 20 April 2020 BST
local RunService = game:GetService("RunService")
local debounce = false

RunService.Heartbeat:Connect( function()
        if debounce then return end
	local diffSeconds = TARGET_TIME - os.time()
	local countdown = os.date( '!*t', diffSeconds ) -- The first argument is important to say we're working in UTC so no offsets get applied

    -- here you would update a GUI or whatever it is you need to do
	script.Parent.Text = ( '\n%i Days\n %i Hours\n %i Minutes\n %i Seconds' ):format(countdown.yday - 1, countdown.hour, countdown.min, countdown.sec)

	if diffSeconds <= 0 then
               debounce = true
		script.Parent.Text = "Are You Ready?"
		wait(3)
		script.Parent.Text = "The Winner Of The Roblox Development Building Competition Is..."
		wait(1)
		script.Parent.Text = "3"
		wait(1)
		script.Parent.Text = "2"
		wait(1)
		script.Parent.Text = "1"
		wait(3)
		script.Parent.Text = "IDONKNOWANYMORE12 - Congratulations!"
		wait(10)
		script.Parent.Text = "Creators:\nBuilder - Aiden_12114\nScripter - Aiden_12114"
		wait(12)
		script.Parent.Text = "Now You May Leave."
                debounce = false
	end
end)

Still doesn’t work. It just repeats the countdown all over again.

Try now, I just edited it. I didn’t put the debounce at the top.

1 Like

Thank you so much! You just saved me big time from 170 angry members lol.

1 Like

No problem! Good luck :slight_smile:

What you are forgetting is runservice heartbeat is like an actual heartbeat, it doesn’t stop pumping the same function when you want it to.

Instead you should compare the difference between the target time and the current time, once the time exceeds said value you should then either:

  • A. Check the difference and do it based on that.
  • B. Start the countdown as a seperate function, then simply check if one already exists.

e.g.

local target = tick() -- get this as your dates time, we're using tick for the simple ease of it.

RunService.Heartbeat:Connect( function()
	if tick() - target > 30 then
		script.Parent.Text = "Whatever"
	elseif tick() - target >= 0 then
		script.Parent.Text = "Are you ready, event is now!"
	else
		script.Parent.Text = "We aren't at the event yet.."
	end
end)

With this method you’ll make use of the heartbeat instead of just ignoring it and having a useless loop ^^

Yes I would do something like that, but I did not want to scrap the OP’s code. Additionally, you should disconnect the event after the “Are you ready” if you don’t need it to repeat as the heartbeat event is no longer needed in that case.

It depends if you want to use the Heartbeat to do other things, you shouldn’t have to make the heartbeat redundant once it suits one of your needs - else I may as well have four scripts doing it.