Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

I belive this is causing my game to crash :? then All I do is run them with resume .

-- Coroutines
local ObjToMouse = coroutine.create(function(Obj)
while true do 
if (Mouse.Target ~= CurrentObject) and (Client_Char.Torso.Position - Mouse.Hit.p).magnitude <=26 then
wait(0.01)
Obj.position = Mouse.Hit.p;
print("Coroutine Running")
end
end
end)

local MaxCircP = coroutine.create(function(MaxC)
while true do 
wait(0.01);
MCBodyPos.position = Client_Char.Torso.Position+Vector3.new(0,-2.8,0);
end
end)
-- Coroutines

Please tell me the problem if you can.

2 comments

0

The thing is the structure of my coroutine wrong.

0

I don't understand the question..

1 answer

✓ Accepted answer

while true do if (Mouse.Target ~= CurrentObject) and (Client_Char.Torso.Position - Mouse.Hit.p).magnitude <=26 then 05 wait(0.01) 06 Obj.position = Mouse.Hit.p; 07 print("Coroutine Running") 08 end end look closely at this loop. games crash when a loop runs infinitely without a wait.

sure, this loop has a wait, but that wait ONLY executes if Mouse.Target ~= CurrentObject, meaning that when it's false, the loop won't wait and crash the game.

fixing is easily done; put a wait() before the end of the while true do, like this:

while true do if (Mouse.Target ~= CurrentObject) and (Client_Char.Torso.Position - Mouse.Hit.p).magnitude <=26 then 05 wait(0.01) 06 Obj.position = Mouse.Hit.p; 07 print("Coroutine Running") 08 end] wait(1) end

This discussion is preserved as it was. New answers, comments, and votes are closed.