Game freezes when touched a union?

I think I did put in a wait() but ima check that

I put in a wait(1) before already

~~
if pickedmap == 6 then
workspace.Switching.killparts.Script.Disabled = false
workspace.Switching.killparts.Transparency = 0
workspace.Switching.a.Transparency = 0
workspace.Switching.a.CanCollide = true
workspace.Switching.b.Transparency = 0
workspace.Switching.b.CanCollide = true
workspace.Switching.c.Transparency = 0
workspace.Switching.c.CanCollide = true
workspace.Switching.d.Transparency = 0
workspace.Switching.d.CanCollide = true
workspace.Switching.e.Transparency = 0
workspace.Switching.e.CanCollide = true
workspace.Switching.f.Transparency = 0
workspace.Switching.f.CanCollide = true
workspace.Switching.g.Transparency = 0
workspace.Switching.g.CanCollide = true
workspace.Switching.Part.Transparency = 0
workspace.Switching.Part.CanCollide = true
game.ReplicatedStorage[“Seconds”].Value = 50
wait(1)
repeat
game.ReplicatedStorage[“Seconds”].Value = game.ReplicatedStorage[“Seconds”].Value - 1
wait(1)
until game.ReplicatedStorage[“Seconds”].Value < 1

	workspace.Switching.killparts.Script.Disabled = true
	workspace.Switching.killparts.Transparency = 1
	workspace.Switching.a.Transparency = 1
	workspace.Switching.a.CanCollide = false
	workspace.Switching.b.Transparency = 1
	workspace.Switching.b.CanCollide = false
	workspace.Switching.c.Transparency = 1
	workspace.Switching.c.CanCollide = false
	workspace.Switching.d.Transparency = 1
	workspace.Switching.d.CanCollide = false
	workspace.Switching.e.Transparency = 1
	workspace.Switching.e.CanCollide = false
	workspace.Switching.f.Transparency = 1
	workspace.Switching.f.CanCollide = false
	workspace.Switching.g.Transparency = 1
	workspace.Switching.g.CanCollide = false
	workspace.Switching.Part.Transparency = 1
	workspace.Switching.Part.CanCollide = false
end

~~

Is this the only loop in the script? If so I think there’s another loop in a script that you didn’t add a wait()

I only see no wait() in my main while true do, but inside that are only a few if statements and all of those have their own wait() so that shouldn’t be a problem right?

Can you post the part of your script which happens when you touch an union? Maybe there’s a loop there without a wait()

There is no script for when you touch the union

If I use workspace.Switching:GetChildren() without anything in the brackets, will it automatically select all of the children?

If you want the children, do a pairs loop. You don’t really want to put anything inside of :GetChildren() as it just returns a table with all children of a given instance.

Could you tell me a little more about in pairs loop? Because I don’t yet really understand that one

There’s plenty of tutorials online, just a quick google search will do the trick.

Except for the upgrade of the script using in pairs loop, do you have any idea why the game is freezing right when i touch the union even though there’s no function connected to touching it?

It’s probably because it’s throttling, just add a wait() which should just stop it from doing that.

If it isn’t that, mind showing us any other loops in your code?

Okay thanks, it somehow helped, can roblox literally freeze by running an empty loop over and over? because everything inside the while true do was in an if statement and 100% of those had a wait()

Did you say that the wait() was inside an if statement? If that is the case, the wait() won’t be run at all if the condition to the if statement doesn’t apply. Try putting a wait() at the end of the while loop, outside the if statement.

Yeah I did that and it worked already, was wondering, can roblox literaly freeze on an empty while true do?

Yes, roblox can freeze if a while loop was running continuously without a delay. This post has a helpful reply that explains what a script timeout is.

Yes, and if it does freeze, make sure to open a recovery file that should pop up when you start up Studio again, or you’ll probably lose all your progress you had since the last save.

it was player that froze not studio, but it’s fixed by adding a wait(0.2)

Oh. Well you will forget to add a wait sometime when creating a loop (i literally did that yesterday) so when that happens make sure to use the recovery file. It can save you alot of time.:+1:

Also i don’t think you need the ‘0.2’, just a wait() should do it.

Oh, okay thanks for the tip – 30 char ://