Hello,
I developed a terrain generating script, and have decided first to implement organizing the regeneration/ degeneration of the terrain by functions, and putting them into ReplicatedStorage, where my main script can reference it. When I ran my game, I had found out that the lag had reduced by a lot. I was planning to test out another optimization script, but I got an error:
20:33:15.746 - ReplicatedStorage.Generation:64: '}' expected (to close '{' at line 2) near 'print'
20:33:15.747 - Requested module experienced an error while loading
Below is the code in ReplicatedStorage, the script called Generation. Following that is the main script in my Workspace that I used to put the functions together:
return { Speed = 5, -- Keep between 1 and 5 Generate = function(Self) --set block count local howManyClones= 0 --create a group called "DirtBlockCloneGroup" local dirtBlockCloneModel= Instance.new("Model",game.Workspace) dirtBlockCloneModel.Name= "DirtBlockCloneGroup" for timer= 1,0,-1 do --timer that counts from 3/ any # to 0 by seconds wait(1) print(timer) if timer== 0 then print("Done.")--ends timer, then does action below end--end if end--end for x0= game.Workspace.DirtBlock.Position.X y0= game.Workspace.DirtBlock.Position.Y z0= game.Workspace.DirtBlock.Position.Z --sets whatever position the original dirt block is in, stores in variables local original= Vector3.new(x0,y0,z0) local zIncr= 3 --increments new clone blocks by changing z coordinate --line below checks and gets testing plate size local zSizeBase= game.Workspace.BasePlate.Size.Z local zSizeCheck= 3--baseplate comparison, so clone won't pass plate boundaries local xSizeBase= game.Workspace.BasePlate.Size.Z local xSizeCheck= 3 local xIncr= 3 for i= 1,4 do--sets how many layers of bricks for i= 1,(xSizeBase/3) do-- because it increments by 3 studs while zSizeCheck<zSizeBase do clone= game.Workspace.DirtBlock:Clone()-- creates clone clone.Name= "DirtBlockClone" -- changes name of dirt block clone.Parent= game.Workspace.DirtBlockCloneGroup --adds the instance into the Workspace clone.Position= Vector3.new(x0,y0,z0-zIncr) clone.BrickColor= BrickColor.new("Black") howManyClones= howManyClones+1--cloned brick counter zIncr= zIncr+3-- ex. 3 away from original, 6 away, 9 away etc. zSizeCheck= zSizeCheck+3 end zSizeCheck= 0--these scripts reset the position, so it won't shift zIncr= 0 x0= x0+3 wait(0)--delay to minimize lag, edit between dev and release end end y0= y0+3-- goes to the next level, 3 studs up x0= game.Workspace.DirtBlock.Position.X-- resets at original point end print(howManyClones)--prints the number of bricks end,--end function generate Degenerate= function(Self) wait(0) game.Workspace.DirtBlockCloneGroup:Destroy() wait(0) end--end function Degenerate }--end of return at very beginning
local Generation= require(game.ReplicatedStorage.Generation) while true do --create terrain Generation:Generate()-- or regenerate --allow player to play buy freeing them from spawn area game.Workspace.SpawnArea.SpawnBaseBottom.CanCollide= false game.Workspace.SpawnArea.SpawnBaseBottom.Transparency= 1 --this period is the playing time before the map resets for timeToReset= 100,0,-1 do wait(1) test2= Instance.new("Hint",game.Workspace) test2.Text= "Map reset and respawn deactivation in: "..tostring(timeToReset) end--end for --players go back when map is regenerating game.Workspace.SpawnArea.SpawnBaseBottom.CanCollide= true game.Workspace.SpawnArea.SpawnBaseBottom.Transparency= 0.75 target= CFrame.new(60.5,3358,84.5) for i, player in ipairs(game.Players:GetChildren()) do if player.Character and player.Character:FindFirstChild("Torso") then player.Character.Torso.CFrame= target+ Vector3.new(i*2,0,0) end end --clear terrain Generation:Degenerate() endend y0= y0+3-- goes to the next level, 3 studs up x0= game.Workspace.DirtBlock.Position.X-- resets at original point end print(howManyClones)--prints the number of bricks} end,--end function generate Degenerate= function(Self) wait(0) game.Workspace.DirtBlockCloneGroup:Destroy() wait(0) end--end function Degenerate }--end of return at very beginning
One of my attempts was to follow exactly what the message had said and put a brace after the indicated line:
The only other option I had was to avoid ReplicatedStorage and put all the code into a single, main script in the workspace.
Edit: The pre-class object in the code was supposed to be normal text; below it was the attempted script.