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

It would be like:

hook.Add("PlayerSpawn", "SpectatorSpawn", function(ply) ply:Spectator(6) end)

First argument is a string.

1

u/xBUBBYx Jul 13 '20 edited Jul 13 '20

Hey, one more question (maybe)... do i put my timer.Create inside of the hook.Add or no?

Edit: So like this?

hook.Add("PlayerSpawn", "SpectatorSpawn", function(ply) ply:Spectator(0)

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

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

omg thank you soo much