So im scripting this weapon system, and every time i fire a remote event the loop gets faster, example :
elseif TP1.Name == "UV" then
if TP2 == "On" then
if TP1.Battery.Value >10 then
print("Set1")
TP1.CurrentlyOn.Value = true
end
elseif TP2 == "Off" then
print("SetOff")
TP1.CurrentlyOn.Value = false
end
end
coroutine.wrap(function()
while task.wait(0.8) do
if TP1.CurrentlyOn.Value == true then
print("AE")
end
end
end)()
Because each time the event is fired a new coroutine is created.
elseif TP1.Name == "UV" then
if TP2 == "On" then
if TP1.Battery.Value >10 then
print("Set1")
TP1.CurrentlyOn.Value = true
end
elseif TP2 == "Off" then
print("SetOff")
TP1.CurrentlyOn.Value = false
end
end
coroutine.wrap(function()
while task.wait(0.8) do
if TP1.CurrentlyOn.Value == true then
print("AE")
end
end
coroutine.yield()
end)()
You can either add a yield like I have above, or just remove the coroutine.wrap() call entirely.
elseif TP1.Name == "UV" then
if TP2 == "On" then
if TP1.Battery.Value >10 then
print("Set1")
TP1.CurrentlyOn.Value = true
end
elseif TP2 == "Off" then
print("SetOff")
TP1.CurrentlyOn.Value = false
end
end
coroutine.wrap(function()
while task.wait(0.8) do
if TP1.CurrentlyOn.Value == true then
print("AE")
else
break
end
end
end)()
It’s possibly because there isn’t a break statement to break out of the loop.