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

How do you remove something from a folder if it's been selected from math.random? [SOLVED]

I am making a game with character customization, and so that players don't get put in the same area, I have script that clones a new area whenever a player joins, except it only clones it once, and not every time someone joins, I have it set up so that it names the model the player's name once they join, but I'm trying to figure out how to remove a spawn point from the folder that holds the spots where the model can be cloned this is the code.

local AvailableArea = game:GetService("ReplicatedStorage").SpawnPartsForCustomize

local chosenArea = AvailableArea:GetChildren()

local mathClonedArea = chosenArea[math.random(#chosenArea)]

local isAble = mathClonedArea:WaitForChild("IsFilled")

local clonedArea = mathClonedArea:Clone() clonedArea.Parent = workspace

2 comments

0

Please use Lua Code Blocks so your code is easier to read.

0

local mathClonedArea = chosenArea[math.random(1,#choseArea)]

2 answers

If you save the math.random value to a variable, you can index and destroy the map just like you would when choosing it.

local AvailableArea = game:GetService("ReplicatedStorage").SpawnPartsForCustomize

local chosenArea = AvailableArea:GetChildren()

local randomArea = math.random(#chosenArea)

local mathClonedArea = chosenArea[randomArea]

...

chosenArea[randomArea]:Destroy()

Something like this would work, where you clone the area then remove it from where it is so it can't be used again.

randomval = math.random(#chosenArea) local mathClonedArea = chosenArea[randomval]

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