RobloxScripterAI
Discord ↗
Link Copied to Clipboard
×
"make it so instead of new instance parts it gets folder children and uses if child is basepart"
To modify the last example so that it operates on existing parts within a folder rather than creating new parts, you can iterate over the children of a specified folder. If a child is a `BasePart` (which includes `Part`, `WedgePart`, `MeshPart`, etc.), you can then assign a random quality value to it. Here's how you might adjust the script: ```lua local folder = Instance.new("Folder", game.Workspace) folder.Name = "QualitySettings" local qualities = {"None", "Low", "Medium", "High", "Very High"} for i, quality in ipairs(qualities) do local stringValue = Instance.new("StringValue", folder) stringValue.Name = quality stringValue.Value = quality end local function getRandomQuality() local index = math.random(1, #qualities) return qualities[index] end -- Assuming there's an existing folder named "Parts" in Workspace with parts in it local partsFolder = game.Workspace:FindFirstChild("Parts") if partsFolder then for i, child in ipairs(partsFolder:GetChildren()) do if child:IsA("BasePart") then -- Check if the child is a BasePart local quality = getRandomQuality() local qualityValue = Instance.new("StringValue", child) qualityValue.Name = "Quality" qualityValue.Value = quality end end else warn("Parts folder not found") end ``` This script first checks if the "Parts" folder exists within the Workspace. If the folder exists, it iterates over each child within the folder. For each child that is a `BasePart`, it assigns a random quality from the predefined list by creating a `StringValue` on the part to store the quality level. If the "Parts" folder does not exist, it outputs a warning message. This approach allows you to dynamically assign properties to existing parts in the game environment without creating new instances.