UnbindFromRenderStep code samples broken due to incorrect use of pcall

The RunService:UnbindFromRenderStep function code samples are both broken due to incorrectly using the pcall function.


The issue lies on line 3 of the first code sample and line 12 of the second.

local success, message = pcall(RunService:UnbindFromRenderStep("binded name"))
Error

image

To fix this, make sure to wrap pcall around a function. Example:

local success, message = pcall(function() RunService:UnbindFromRenderStep("binded name") end)

I’ve re-written both samples to correctly work.

Sample 1
local RunService = game:GetService("RunService")


local Success, Message = pcall(function() RunService:UnbindFromtRenderStep("drawImage") end)

if Success then
	
	print("Success: Function unbound!")
	
else
	
	print("An error occurred: " .. Message)
	
end
Sample 2
local RunService = game:GetService("RunService")


-- Step 1: Declare the function
	
	function printHello()
		
		print("Hello")
		
	end
	
-- Step 2: Bind the function
	
	RunService:BindToRenderStep("Print Hello", Enum.RenderPriority.First.Value, printHello)
	
-- Step 3: Unbind the function
	
	local Success, Message = pcall(function() RunService:UnbindFromRenderStep("Print Hello") end)
	
	if Success then -- if the function was unbound
		
		print("Success: Function unbound!")
		
	else -- if it wasn't
		
		print("An error occurred: " .. Message)
		
	end

Additionally there is a spelling mistake in the description, misspelling "every" as "ever".

image

should be

image

context:

Given a name of a function sent to RunService:BindToRenderStep , this method will unbind the function from being called during RenderStepped. This is used to unbind bound functions once they are no longer needed, or when they no longer need to fire ever step .

1 Like

I’ve corrected the API doc page and the sample accordingly; thank-you for noticing this :slight_smile:

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.