r/GLua • u/xBUBBYx • Jul 13 '20
Delay in Lua
Guys, I am a beginner programmer and I need a way to delay a function after a ply: string. My situation is that I want a player to spawn in spectator mode, and after some amount of seconds I want them to switch to a normal player with all my scripts and stuff. Thank you!
3
Upvotes
1
u/Dak_Meme Jul 13 '20
You can make timers with: https://wiki.facepunch.com/gmod/timer.Create
You can also do CurTime() comparisons within hooks such as "Think".
For your case timers are probably the way to go.
1
u/Dak_Meme Jul 13 '20
Try timer.Create( "MyTimerName", 1, 5, function() print("Hello") end)
You also don't need timer.Start in this instance, timers are started when created. timer.Start is to restart paused timers. Sorry for formatting, on mobile.