How to make a repeat until stop when it touches something?

I want to make a repeat until loop until my bullet touches something. Here is my script so far `local function Ontrigger()
local bullet = script.Parent.Bullet:Clone()
local rotationz = bullet.Rotation.Z
local roationy = bullet.Rotation.Y
local rotationx = bullet.Rotation.X

bullet.Transparency = 0
bullet.Parent = game.Workspace
bullet.LinearVelocity.Enabled = true
	print("not false")
	bullet.Rotation =,roationy,rotationz)
until *My bullet touches something*



how would I do this?
any feedback appreciated!!!

oh and a way that allows me to check what is being touched as well would be good!

Connect your bullet to a simple .Touched event before you start your repeat loop.

local touchedSomething = nil

  touchedSomething = hit

Now you can just make your repeat loop end at:

until touchedSomething
1 Like

Do not use .Touched, it’s very bad.
Instead, you should use :GetTouchingParts every X amount of time. This is a lot more reliable and also means you don’t have to worry about cleaning up events you make, which is a plus.

local RunService = game:GetService("RunService")
local Heartbeat = RunService.Heartbeat

local Hit


while true do
    Hit = bullet:GetTouchingParts()[1]

    if Hit then

    Heartbeat:Wait() -- Wait 1 frame.
1 Like

If it’s something to consider, using a module like FastCast makes life easier. It uses raycasting which is very performant, allows you to render bullets (runs in Heartbeat), has bullet physics, and gives you full control of the bullet (you can pause, resume, accelerate, and etc.).

You’re absolutely right. I’ve never touched the module myself, but I know a lot of games have used it and it is made well.