Hi! :D How do I make a loop run until an event fires? In my case I need the loop on line 13 to run until the BPos.ReachedTarget event fires, in human words, I need the Body gyro to rotate at the part until the Body position reached the target. The script I made doesn't stop the loop. Any suggestions?
local RunService = game:GetService('RunService')
local p = workspace.p2
local init = p.CFrame
local BPos = p.BodyPosition
local BGyro = p.BGyro
local moving = true
BPos.Position = workspace.p1.Position
BPos.ReachedTarget:Connect(function()
print('a') -- For checking
moving = false
end)
while moving do
lookAt = CFrame.new(p.Position, workspace.p1.Position)
BGyro.CFrame = lookAt
RunService.Heartbeat:Wait()
end
Thanks in advance ;)

1 comment
The loop does stop when moving is set to false.