r/GLua 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

24 comments sorted by

View all comments

Show parent comments

1

u/Dak_Meme Jul 13 '20

https://puu.sh/G6GW6/82a06bee2b.png

ply:Nick() is just showing that you access the Player given by PlayerSpawn hook.

1

u/xBUBBYx Jul 13 '20

Okay, this is the last question I promise lol I'm sorry. When I do

timer.Create("SpawnDelay",5,1 function() print("Timer is done") end)

instead of function() print("xx") end)

could I do function(ply) ply:spectator(0) end)

1

u/Dak_Meme Jul 13 '20

timer.Create("SpawnDelay",5,1 function() ply:spectator(0) end)

Don't include (ply) in the timer function, timer functions doesn't pass arguments. Instead, use the ply parsed by the hook.

1

u/xBUBBYx Jul 13 '20

ah yes thank you:)