Advertisement
oopsrainbow4

Making Countdown on Screen

Apr 7th, 2023
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.90 KB | None | 0 0
  1. -- Making countdown on Screen
  2.  
  3. -- Add RemoteEvent in ReplicatedStorage
  4.  
  5. -- ServerScriptService
  6. local ReplicatedStorage = game:GetService("ReplicatedStorage")
  7. local countdownEvent = ReplicatedStorage:WaitForChild("CountdownEvent") -- RemoteEvent
  8.  
  9. local secondRemaining = 20
  10.  
  11. for count = secondRemaining, 1, -1 do
  12.     countdownEvent:FireAllClients(count)
  13.     wait(1.0)
  14. end
  15.  
  16. -- LocalScript in ScreenGUI
  17. local ReplicatedStorage = game:GetService("ReplicatedStorage")
  18. local countdownEvent = ReplicatedStorage:WaitForChild("CountdownEvent") -- RemoteEvent
  19.  
  20. -- Get the ScreenGui and the TextLabel
  21. local screenGui = script.Parent
  22. local countDisplay = screenGui.ShowCountdown
  23.  
  24. local function onTimerUpdate(count)
  25.     -- Set the TextLabel to match the incoming count
  26.     countDisplay.Text = count
  27. end
  28.  
  29. -- Call "onTimerUpdate()" when the server fires the remote event
  30. countdownEvent.OnClientEvent:Connect(onTimerUpdate)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement