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

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

Asked by 4 years ago
Edited 4 years ago

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

0
Please use Lua Code Blocks so your code is easier to read. killerbrenden 1537 — 4y
0
local mathClonedArea = chosenArea[math.random(1,#choseArea)] Ziffixture 6913 — 4y

2 answers

Log in to vote
0
Answered by
ArtBlart 533 Moderation Voter
4 years ago

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.

Ad
Log in to vote
0
Answered by 4 years ago

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

Answer this question