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 :]
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 :]
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:
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.
2 comments
I didn't quite understand the question. Are you trying to use a Touched event to stop a repeat loop?
yeah :]