NSKuber

Exercise 7 Bonus 2

Apr 1st, 2021 (edited)
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.76 KB | None | 0 0
  1. local worldInfo = worldGlobals.worldInfo
  2.  
  3. local importantValue = 0
  4.  
  5. worldGlobals.CreateRPC("server", "reliable", "SetImportantVariable",
  6.     function(newValue)
  7.         importantVariable = newValue
  8.     end
  9. )
  10.  
  11. worldGlobals.CreateRPC("client", "reliable", "RequestImportantVariable",
  12.     function()
  13.         if worldInfo:NetIsHost() then
  14.             worldGlobals.SetImportantVariable(importantVariable)
  15.         end
  16.     end
  17. )
  18.  
  19. -- Each player requests the important variable upon joining
  20. worldGlobals.RequestImportantVariable()
  21.  
  22. -- Only the host increases the important value, and he sends it to everyone
  23. if worldInfo:NetIsHost() then
  24.     while true do
  25.         Wait(Delay(5))
  26.         importantValue = importantValue + 1
  27.         worldGlobals.SetImportantVariable(importantVariable)
  28.     end
  29. end
Add Comment
Please, Sign In to add comment