Im so scared to try this:
while wait(3) do
end
Update: I want a loop to run for x amount of time, not delay running. I need it to run exactly x seconds before it becomes nil, and out of that timeframe it is nil.
Im so scared to try this:
while wait(3) do
end
Update: I want a loop to run for x amount of time, not delay running. I need it to run exactly x seconds before it becomes nil, and out of that timeframe it is nil.
To do this you IN ONE SERVER SCRIPT you will need a Bindable Event. If you are doing Server Script to Local Script (vice versa) you need to use Remote Event.
This is the code.
local BindableEvent = game.ReplicatedStorage.Event
local length = 100 -- timer length
local done = false -- will be true once the timer is done.
local function timer()
for time = length, 0, -1 do
wait(1)
end
done = true
end
BindableEvent.Event:Connect(timer)
BindableEvent:Fire() -- tells the BindableEvent.Event to connect/start the timer.
repeat
wait()
-- your code here
until done
Don't forget to create a bindable event in Replicated Storage.
So whats going on here? well the bindable event allows you to run two loops at once essentially, i.e. it creates different script threads. It also allows you to talk between server scripts.
That does not work as I intend
I have edited it and i think i have answered your question.
You could just use BindableEvent:Wait()
-1. Too many comments, makes it harder to read. I can reconsider my downvote once the readability of the code is improved.
I have edited the code, I hope it is easier to read now sjr04Alt.
This discussion is preserved as it was. New answers, comments, and votes are closed.
1 comment
Don't use wait() as a loop's condition. Read this wonderful document written by one of the scriptinghelpers discord server moderators: https://docs.google.com/document/d/1ieZ8OzXPiXe3R7rs_xWmYZOnhQevlagN0ZWwoj_zKP4/edit