Script prevents me from loading studio or crashes studio

Currently, I have a script in the workspace that is supposed to place a texture on everything in the game. When I have the script disabled, I am able to load in, but when it’s enabled, studio freezes or crashes.

https://streamable.com/tcji6n

Here is the content of the script:

print("loaded")
for i, v in pairs(workspace:GetDescendants()) do
    if v:IsA("Part") and v.TopSurface == Enum.SurfaceType.Studs then
        local newStuds = workspace.Studs:Clone()
        newStuds.Name = "Studs"
        newStuds.Parent = v
        v.BottomSurface = Enum.SurfaceType.Inlet
        --newStuds.StudsPerTile
    end
end

That’s probably because your computer can’t handle it.

You should already have the texture on all of the parts, so you should just run your code in your command bar.

Before I added the comment, it worked without crashing

Not 100% why it started crashing, but after using version history to revert the game everything is good again.

I think I know the issue.

You’re cloning workspace.Studs for every basepart; the issue with that is there’s 2 workspace.Studs and one of them is a script.
Basically, you (may have) created a recursive script that clones itself (and starts running again) for every basepart that exists; then, all of those will also run, creating an infinite loop and causing Studio or the game to freeze indefinitely.

Try renaming or moving your script; I’d recommend placing it in ServerScriptService since it doesn’t reference any parents/children anyways, so you shouldn’t even have to change anything.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.