Yield with a timeout and a condition?

as the tittle says

what im trying to do is after pressing a button the user have to select a part before using the plugin

right now i have it so the plugin deselects everything the user selected before hand and now i need the script to yield until the user has selected a part and then return that part soo i can use it later

any help is appreciated!

just repeat task.wait until selectedInstance

Create a bindable event that fires when a user selects a part and returns the part they selected. Then you can do something like:

--replace OnClick with your button click event name
button.OnClick:Connect(function()
	--partSelected is your bindable event that fires on part selection
	local part = partSelected.Event:Wait()
	print(part)
end)

The above code will wait forever until a part gets selected after the button press. You may want to add extra logic so for example, if they press another button to go back, you stop waiting/cancel the process.

You can do this by chaining together event/signal logic, here’s an example of exactly that of one of my older posts, where I chained together two events, a timeout event and an actual event, to create a “timed event”:

1 Like