Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to use touched event on repeat until? Any help?

Hi! I've got a question, how to use touched event on repeat until? for example :

repeat
print("1")
wait(1)
until   --right here I have no ideas how to continue it

Thank you for every answer :]

2 comments

0

I didn't quite understand the question. Are you trying to use a Touched event to stop a repeat loop?

0

yeah :]

1 answer

✓ Accepted answer

You cant directly use Part.Touched directly, as it is an event.


You have 2 solutions for this:

1- Use BasePart:GetTouchingParts

It returns a Table containing all parts currently touching the basepart. You can use a # before the table to get the number of contents(in this case, touching parts):

local touching = Part:GetTouchingParts()
print(#touching)

2- Use a variable and the Part.Touched event. You can set a variable to true once a touch start:

local touching = false
part.Touched:Connect(function()
	touching = true
end)

You can use any of this on the condition of your loop:

repeat
print("1")
wait(1)
until #Part:GetTouchingParts() > 0

or

local touching = false
part.Touched:Connect(function()
	touching = true
end)

repeat
print("1")
wait(1)
until touching

API Reference:

BasePart:GetTouchingParts

Tables

BasePart.Touched

Events


If this solves your question, please mark this answer as accepted

This discussion is preserved as it was. New answers, comments, and votes are closed.