Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Selecting random obstacles from Server Storage?

Let me explain what this is. So, basically what happens is:

ServerStorage > Clones > Stage1C > Set1 Set2 Set3 Set4

basically it selects 1 of the Set1,2,3, and 4. Each set inside has several obstacles across the entire map that are displayed for players to run. I don't want it to work that way anymore, how can I make it so that it goes to each Set but instead of selecting the entire set and all children inside, it only selects 1 child inside each set and places them all in the course for the player to play?

my apologies if I didn't give enough info. If you need more help understanding here is a picture of where I place all 4 sets:

https://imgur.com/55YFdzE

and inside each set, there will be 4 obstacles that every round 1 of them shows visible for the player to run throughout the course.

Core.Stage:ClearAllChildren();
	Stage = Stage:Clone();
	local randStageMap = game:GetService("ServerStorage"):FindFirstChild("Clones"):WaitForChild("Stage"..stageNumber.."C"):GetChildren()
	local actualMap = randStageMap[math.random(1,#randStageMap)]:Clone()
	actualMap.Parent = Core.Stage
	for _,obj in pairs(Stage:GetChildren()) do obj.Parent = Core.Stage; end;
	

2 comments

0

What error did it give?

0

There isn't any error. It just selects 1 of the 4 sets for the player to play. Instead, I want it to select 1 obstacle from inside of each "set1,2,3, and 4". There will be 4+ models inside each Set12,3,4.

1 answer

The for loop you are making is getting all the children and putting it in the stage. You might want to do this.

local children = Stage:GetChildren()
local random = math.random(1,x) --x is amount of children in the set
children[random].Parent = Core.Stage

This discussion is preserved as it was. New answers, comments, and votes are closed.