Game freezes when touched a union?

Hey everyone!

Today I published a new update including new stages etc. for my randomized obby game, however, whenever I touch a union of bricks i made, the game just freezes and i have to alt+f4 to leave. Is this a common issue? Does anyone know why this could be happening and how to fix it?

Does that union has any scripts?

The union itself has no script, the only script that has something related to it is the randomizing script that changes the cancollide to true and transparency to 0 when the stage gets chosen.(and cancollide to false back again and transparency back to 1 obviously)

Is there any error in the output?

It just tells me: Script timeout: exhausted allowed execution time

Just what I expected. Check that script(especially while loops and repeat loops) and see if those loops have wait() in them. If not then add a wait(–time waited).

What exactly will that wait() do?

Well in a while or repeat loop, you don’t know how much times it will loop(maybe infinity idk). Because the computer runs commands fast so it will get that error. wait() delay the script for a certain amount of time so it won’t error.

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?