Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How to change a property of some random parts in a Folder?

Asked by 5 years ago
Edited 5 years ago

If I have a folder with 50 parts, all named "Part". How do I choose 10 random parts in that folder and change a property, like making them half invisible (Transparency = 0.5). Then after like 5 seconds I change the property of the same parts back (Transparency = 0) and choose some other random parts and change the property of them (Transparency = 0.5). [EDIT] Just so you know, person who read this, by the time I edit in this part I've got three answers, and not a single one of the people that have answered has read my question properly. I want to change back the property that I've changed after five seconds and then do the same thing again! With other parts! And I have written that all the parts have the same parent, a folder, named "Folder"!

3 answers

Log in to vote
0
Answered by
KDarren12 705 Donator Moderation Voter
5 years ago

This is very easy to do with for. You can loop something an amount of times, like 10, for example:

for i = 1,10 do
workspace.FolderName.Part.Transparency = .5
end

I hope I could be of help to you, if not, please tell me.

0
Incorrect. That's not random. DeceptiveCaster 3761 — 5y
0
Well what's your take on it genius? ^ Maginatoc -5 — 5y
Ad
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

This may be seen as a inconclusive answer but you may require some assistance.

Such as, getting all the children of folder, unpacking i.e. unzipping the table and applying your desired affect.

Example:

newf = Instance.new("Folder")
x = 50 -- no. of parts to go in your folder

for r = 1, x do -- r for replicate
local parts = Instance.new("Part")
parts.Parent = newf
end

I will finish it later on, sorry.

0
The parts already exist, I've scaled and positioned them as I want and when the game starts I want to change a property of them Spjureeedd 385 — 5y
0
Exxxactly. KDarren12 705 — 5y
Log in to vote
0
Answered by 5 years ago

Sorry for the late answer, I just thought I'd be able to help.

So, first off, get all the parts in a folder or model or something like that. Make sure they have the same parent.

let's assume I have made a variable in this script called "parent", and it's the parent of all the parts. The parent of the parts is located somewhere in workspace

Now, we can do this.

local Parts = parent:GetChildren()

To get 10 random children, we use a for loop. Something along the lines of this:

for index = 1,10 do

This for loop will "count" from 1 to 10, increasing by one every time it loops. The first number is it's starting point and the second is it's ending point. You can add an additional third number to specify by how much you want the for loop to go up every time it runs, but we're not gonna need that here.

Now, what we can do is get a simple random number, and use the "[]" function (no idea what it's called) to get the object in the Folder corresponding to that number (I really don't know how to explain this, I'm sorry)

So we'd end up with something like this

local Children = parent:GetChildren()

for index = 1,10 do local RandomNumber = math.random(1,#Children) local RandomPart = Children[RandomNumber]

-- do stuff

end

Hopefully this helped, and again, sorry for the poor explanation and possibly many grammar mistakes.

0
Please read my question properly before answering Spjureeedd 385 — 5y

Answer this question