Backstory So for loops can be used for many things either that being getting the children of a object or making and event happening a certain amount of times. For me I'm using a for loop to get the children in a object that i will turn its transparency to 1. This script will then will be sent to the server using FE.
Problem
So my actual problem is this. How can i make the for loops for i,v in pairs(char:GetChildren()) do
only happen once. This script is playing mutiple times and then stopping when the player has for looped v enough times. Thank you!
Local Script
01 | game.Workspace.Spart.ClickDetector.MouseClick:Connect( function () |
02 | UIS.InputBegan:Connect( function (Input,gp) |
03 | if Input.KeyCode = = Enum.KeyCode.E and not gp then |
04 | if not en then return end |
05 | en = false |
06 | for i,v in pairs (char:GetChildren()) do |
07 | if i:IsA( "Accessory" ) then |
08 | local BackupAc = v:Clone() |
09 | game.ReplicatedStorage.SRemote 3 :FireServer(hum,root,Mouse.hit,SCircle,char,BackupAc) |
10 | wait( 0.1 ) |
11 | char [ "Left Arm" ] .Transparency = 0 |
12 | char [ "Right Arm" ] .Transparency = 0 |
13 | char [ "Torso" ] .Transparency = 0 |
14 | char [ "Head" ] .Transparency = 0 |
15 | char [ "Left Leg" ] .Transparency = 0 |
Server Script
01 | game.ReplicatedStorage.SRemote 3. OnServerEvent:Connect( function (Player,hum,root,Mousehit,SCircle,char,Backup) |
02 | print (char) |
03 | local tweenInfo 3 = TweenInfo.new( 0.6 ,Enum.EasingStyle.Quad,Enum.EasingDirection.Out, 0 , false ) |
04 | local tweenInfo 4 = TweenInfo.new( 1.5 ,Enum.EasingStyle.Quad,Enum.EasingDirection.Out, 0 , false ) |
05 | char [ "Left Arm" ] .Transparency = 1 |
06 | char [ "Right Arm" ] .Transparency = 1 |
07 | char [ "Torso" ] .Transparency = 1 |
08 | char [ "Head" ] .Transparency = 1 |
09 | char [ "Left Leg" ] .Transparency = 1 |
10 | char [ "Right Leg" ] .Transparency = 1 |
11 | local SCircle = game.ReplicatedStorage.Spectre:Clone() |
12 | game:GetService( "Debris" ):AddItem(SCircle, 2 ) |
13 | SCircle.Parent = workspace |
14 | SCircle.Anchored = true |
15 | SCircle.CanCollide = false |
Try not to pay attention to the actual script but the problem because the script is quite long.
Regards, Bl_ueHistory
If you want to stop after the first Accessory you find, you can use break
to exit the loop early.
If you want to apply your effects to all Accessories simultaneously, you must avoid using wait
inside the for loop and split up your effects into multiple for loops if needed. In your case I expect you want to run lines 33 - 43 only once, after destroying all the accessories -- simply move them outside the for loop to fix that. You'll want to do the same sort of thing for the LocalScript, too.
Minor note: I expect line 7 is erroring in the LocalScript because i
is an integer (you meant v:IsA
not i:IsA
)