I wanna make a lag button, so I made a gui with a localscript to be able to hide a certain amount of trees. I don't know how to make the script. Can someone help me with the script?
You can make the certain trees as a model, and using ipairs loop or for loop and make them invisible. Well, you also can use for loop but I do not recommend because for loop does not know the part names but ipairs loop does collecting instances while for loop is recommended for number usage.
Make the trees you want to hide on the model, and name the model anything if you want. But for my script, you need to name it ToggleTree.
local Trees = game.Workspace.ToggleTree local HidingTrees = false local debounce = false if debounce == true then for i, v in ipairs(Trees:GetChildren()) do debounce = true if HidingTrees == false then HidingTrees = true v.Transparency = 1 v.CanCollide = false else HidingTrees = false v.Transparency = 0 v.CanCollide = true end wait(1) debounce = false end end
Note: some LocalScript does not work in ServerScriptService or Workspace... Incase your LocalScript works make them inside StarterPack or StarterGui.
Also, this is just a sample, you will still need to make it your own
a very handy feature I would use in this case is CollectionService
. this allows you to mark any physical game object with a tag and allows you to retrieve them easily. just select any tree you would like to omit and tag it with something like “high quality”. then, use collectionservice to retrieve these trees and set their transparency to 1 in a single loop when the user hits the button.
I advise you to look up how to use collectionservice yourself if you do not know already. the “tag editor” plugin makes it super easy. if you are still stuck, comment and I will edit in some code tomorrow :)