How do I make the rest of my code run at the same time as my while true loop?
Asked by
7 years ago Edited 7 years ago
I made some code in Filtering Enabled which requires a while loop needed to update a part's position every .1 second. But of course when I'm running the loop, the rest of the code doesn't run which is a problem. Help? I could make another script to loop it but the main script still needs the variable because its F.E.
This is what is in the script: (The while loop is commented)
01 | script.Parent.RemoteEvent.OnServerEvent:Connect( function (Player,mouse,anim,Jailed,Jailed 2 ,Hit,isCaught) |
11 | local Jailed 1 = Player.Character.Tool.Handle |
12 | local attachmentB = Instance.new( "Attachment" ,Jailed 2 ) |
13 | local attachmentA = Instance.new( "Attachment" ,Jailed 1 ) |
14 | attachmentA.Position = Vector 3. new( 1 ,- 0.7 , 0.3 ) |
15 | attachmentB.Position = Vector 3. new( 0 , 0 , 0.3 ) |
18 | local ropeConstraint = Instance.new( "RopeConstraint" ,Jailed 1 ) |
19 | ropeConstraint.Attachment 0 = attachmentA |
20 | ropeConstraint.Attachment 1 = attachmentB |
21 | ropeConstraint.Length = 10 |
22 | ropeConstraint.Visible = true |
23 | ropeConstraint.Color = BrickColor.Black() |
24 | ropeConstraint.Thickness = 0.2 |
25 | ropeConstraint.Restitution = 0.5 |
26 | local caught = Jailed.Humanoid:LoadAnimation(anim) |
30 | script.Parent.Unequipped:Connect( function () |
31 | ropeConstraint:Destroy() |