I have a RunService:BindToRenderStep that I only want to run when a boolean is true. How can I achieve that? Thanks!
local RunService = game:GetService("RunService")
local function renderPreview()
print("Running")
end
RunService:BindToRenderStep("Preview", Enum.RenderPriority.Camera.Value, renderPreview)
Something like this should work to achieve what you’re looking for (condition is the boolean value to change):
local RunService = game:GetService("RunService")
local active = false
local condition = true
local function renderPreview()
print("Running")
end
RunService.Heartbeat:Connect(function()
if condition then
if active then return end -- This is to prevent calling BindToRenderStep multiple times unnecessarily
active = true
RunService:BindToRenderStep("Preview", Enum.RenderPriority.Camera.Value, renderPreview)
else
if active then
active = false
RunService:UnbindFromRenderStep("Preview")
end
end
end)
@Guest_2000123145 Alternatively, if condition is a BoolValue it makes things much simpler:
local RunService = game:GetService("RunService")
local condition = -- Where the BoolValue is located
local function renderPreview()
print("Running")
end
condition.Changed:Connect(function(value)
if value then
RunService:BindToRenderStep("Preview", Enum.RenderPriority.Camera.Value, renderPreview)
else
RunService:UnbindFromRenderStep("Preview")
end
end)