"Press any key" after a few seconds of inactivity

Hello :wave: I’m making a dialogue system with the NPS, and I want that after 5 seconds of inactivity (if the NPC says something and the player will not do anything for 5 seconds), the message “press any key to continue” will appear, which will still gradually change its transparency. But I use -inputBegan:wait(), and I don’t know how to make this system without using events. Here is the code in the dialog script, and in the script that fires when the event is firing. How can this system be easying?

frame.Key.Effect:Fire()
inputS.InputBegan:Wait()
frame.Key.Visible = false

When event firing:

script.Parent.Effect.Event:Connect(function()
script.Parent.Visible = true
wait(5)
if script.Parent.Visible == true then
	script.Parent.TextStrokeTransparency = 0.5
	while script.Parent.Visible == true do
		for i = 70, 20, -1 do
			script.Parent.TextTransparency = i/100
			wait(0.02)
		end
		for i = 20, 70, 1 do
			script.Parent.TextTransparency = i/100
			wait(0.02)
		end
		wait()
	end
	script.Parent.TextTransparency = 1
	script.Parent.TextStrokeTransparency = 1
end
end)
2 Likes

Couldn’t you use TweenService in place of where you fire the event? Or instead of having the event there, you could use the function spawn(FunctionToRun) so that way your effect runs on a separate thread from the script that detects user input. That way the script that detects user input and the script that does your effect will run asynchronously.

1 Like

The dialog creation script is a module script, and the spawn function cannot be inserted

I just tried using spawn in a ModuleScript, and it worked fine.