Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 9 years ago
-- 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.

0
The thing is the structure of my coroutine wrong. Blockeus 68 — 9y
0
I don't understand the question.. Goulstem 8144 — 9y

Locked by BlueTaslem

This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.

Why was this question closed?

1 answer

Log in to vote
0
Answered by 9 years ago

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

Ad