I reckon Roblox added a new method to the list of methods apart of the RBX event signals. The new method in question is ‘once’. I noticed this connection while teaching one of my students. I then attempted to look at this new method on the API, however, I found that it does not currently exist. I logically can conclude that it simply runs an event triggered signal once rather than every time it pulses, but does anyone know of the existence of this new method?
I dont really understand what do you really mean but i think you could achieve this with Debounce or connection:Disconnect()
The new beta docs are your best bet for up to date info
Added to my bookmarks, thanks for the help.
I was referencing the ROBLOX method ‘once’ apart of the events. I was just wondering what exactly that is considering the non-beta documentation does not have any information on it.
I’m not even sure why a Once
method was added.
--ONCE
local Game = game
local RunService = Game:GetService("RunService")
local function OnRenderStep()
--Code.
end
RunService.RenderStepped:Once(OnRenderStep)
--CONNECT
local Game = game
local RunService = Game:GetService("RunService")
local Connection
local function OnRenderStep()
Connection:Disconnect()
--Code.
end
Connection = RunService.RenderStepped:Connect(OnRenderStep)
--WAIT
local Game = game
local RunService = Game:GetService("RunService")
local function Wait(Event)
Event:Wait()
--Code.
end
task.spawn(Wait, RunService.RenderStepped)
It was added for convenience so you wouldn’t have to initialize a variable to disconnect a signal once it fired
Your second example can be replaced with Once
and your third example would only be useful for times where the thread needs to yield
It was added for convenience so you wouldn’t have to initialize a variable to disconnect a signal once it fired
What would have been more convenient is an improvement to Connect
.
local Game = game
local RunService = Game:GetService("RunService")
local function OnRenderStep()
--Code.
end
RunService.RenderStepped:Connect(OnRenderStep, 5) --Optional 'Count' parameter (indicates how many times the event should be listened for).
Your second example can be replaced with
Once
and your third example would only be useful for times where the thread needs to yield
Both are demonstrating Once
alternatives, the third example is yielding an alternate thread of execution.
I didn’t know I could do that.