I am scripting something that requires me to get a random part from a folder and I have looked at posts but to no avail, this is all it should take according to posts. tiles is a variable that is the children of the folder I need to get the part from. Does anyone have this problem and or a solution? Thanks!
When you declared the value of tiles did you get the children. For example did you do local tiles = Folder:GetChildren()
That could be one reason it isn’t working.
One reason I had to come to Dev Forum for this is because my script was the same but then I suddenly got the error. Is there any way to correctly pick a random part then? Because I am at a lost .-.
Just to give you more info, this is the entire script that needs the random tile.
local TileList = game.Workspace.TileList
local tiles = TileList:GetChildren()
local Timer = game.StarterGui.MainUI.Mainframe.Timer
local function FireLasers()
for i = 1,10,1 do
local randomTile = tiles[math.random(1,#tiles)]
print("Tile "..randomTile.Name.." was choosen!")
wait(0.5)
for i = 1,10,1 do
wait(0.01)
randomTile.Transparency = randomTile.Transparency + 0.1
end
randomTile.CanCollide = false
wait(0.5)
for i = 1,10,1 do
wait(0.01)
randomTile.Transparency = randomTile.Transparency - 0.1
end
randomTile.CanCollide = true
wait(0.01)
end
end
local count = 0
for i,v in pairs(tiles)do
if count == randomTile then
--Do what you need to do to the random part random part will be v so if you want to destroy it do v:destroy()
end
count = count + 1
end
If it doesn’t work you might need to change it to
local count = 0
for i,v in pairs(tiles)do
if count == toNumber(randomTile) then
--Do what you need to do to the random part random part will be v so if you want to destroy it do v:destroy()
end
count = count + 1
end
I didn’t test this but I think it will work. Let me know if it works or not.