I just tried to return detected part but can’t because of coroutine is blocking it. Is it possible to return value after coroutine is end but it should not pause main line.
local function hitbox(param)
local hitResult = nil
local hitEnded = false
if humanoid.status.Value ~= "stun" then
coroutine.wrap(function()
local hitable = true
coroutine.wrap(function()
wait(param.hitTime)
hitable = false
end)()
local immune = {player.Character}
while hitable == true and humanoid.status.Value ~= "stun" do
hitResult = hitCalculate(param, immune)
if hitResult then
print(hitResult)
break
end
game:GetService("RunService").Heartbeat:wait()
end
immune = {}
hitEnded = true
end)()
end
if param.retTarget == true then
coroutine.wrap(function() --problem is here
while hitResult == nil and hitEnded == false do
game:GetService("RunService").Heartbeat:wait()
end
if hitResult then
return hitResult --even if I return it will not return to main line
end
end)()
end
end