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
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
break
end
Heartbeat:Wait() -- Wait 1 frame.
end
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.).