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

Is it possible for another part of a script run while you have a for loop?

Asked by 8 years ago

This script crashes studio it does not even run :(

coroutine.resume(coroutine.create(function()
while true do
MagicSym = Instance.new("Part")
    MagicSym.Parent = me.Character.Torso
    MagicSym.Anchored = true
    MagicSym.CanCollide = false
    MagicSym.formFactor = "Symmetric"
    MagicSym.BrickColor = BrickColor.new("New Yeller")
    MagicSym.Transparency = 1
    MagicSym.Name = "MagicSym"
    MagicSym.Size = Vector3.new(30, 1, 30)
    MagicSym.TopSurface = "Smooth"
    MagicSym.BottomSurface = "Smooth"
    MagicSym.CFrame = me.Character.Torso.CFrame*CFrame.new(0,-3, 0)


    d = Instance.new("Decal")
    d.Name = "Circle"
    d.Parent = MagicSym
    d.Face = "Top"
    d.Texture = "http://www.roblox.com/asset/?id=214848393"
    p = Instance.new("Decal")
    p.Name = "Circle"
    p.Parent = MagicSym
    p.Face = "Bottom"
    p.Texture = "http://www.roblox.com/asset/?id=214848393"
end
end
)
)
while true do
    for loop = 1, 50 do
    MagicSym.CFrame = MagicSym.CFrame *CFrame.Angles(0, 0.005, 0)
    wait(1/25)
wait()
end


end

This is what I made of it. The only problem is the crashing

2 answers

Log in to vote
0
Answered by
Nickoakz 231 Moderation Voter
8 years ago

Coroutines.

http://wiki.roblox.com/index.php?title=Coroutines

coroutines.resume(coroutine.create(function()
while true do
print("looping with each other")
wait()
end
end))
while true do
print("its just one script")
wait()
end

Reminder. DON'T DO THIS..

script.Parent.Touched:connect(function()
coroutines.resume(coroutine.create(function()
while true do
print("looping with each other")
wait()
end
end))
end)

You will lag the server because when you create a co-routine, it's creating another thread. Too many thread's will degrade server performance. You'll need to ask another question on how to kill co-routines.

0
Yeah I remember doing the same mistake a while back, don't do it fdfxd 50 — 8y
0
Although the game runs perfectly fine, any server sided script is slower with that mistake. Nickoakz 231 — 8y
Ad
Log in to vote
0
Answered by 8 years ago
--If you mean you want the script to run with a infinite loop effectively then add a 
--term from Rbx.Lua called break****
--Or if you mean just run it with no infinite loops just add a wait() in between while true do wait()
coroutine.resume(coroutine.create(function()
while true do
MagicSym = Instance.new("Part")
    MagicSym.Parent = me.Character.Torso
    MagicSym.Anchored = true
    MagicSym.CanCollide = false
    MagicSym.formFactor = "Symmetric"
    MagicSym.BrickColor = BrickColor.new("New Yeller")
    MagicSym.Transparency = 1
    MagicSym.Name = "MagicSym"
    MagicSym.Size = Vector3.new(30, 1, 30)
    MagicSym.TopSurface = "Smooth"
    MagicSym.BottomSurface = "Smooth"
    MagicSym.CFrame = me.Character.Torso.CFrame*CFrame.new(0,-3, 0)


    d = Instance.new("Decal")
    d.Name = "Circle"
    d.Parent = MagicSym
    d.Face = "Top"
    d.Texture = "http://www.roblox.com/asset/?id=214848393"
    p = Instance.new("Decal")
    p.Name = "Circle"
    p.Parent = MagicSym
    p.Face = "Bottom"
    p.Texture = "http://www.roblox.com/asset/?id=214848393"
--A break here--The break word should make it render a bit between the script so that the script can run with the infinite loop.
break 
end
end
)
)
while true do
    for loop = 1, 50 do
    MagicSym.CFrame = MagicSym.CFrame *CFrame.Angles(0, 0.005, do--So we do break between the waits
    wait(1/25)
break
wait()
end


end --If this helped leave an upvote or an Accept much appreciated.

Answer this question