I've hit a wall when it comes to this area. What ever I do it always shows the Serial Number for the Part. example: (if I had 2 Parts in my Array, it would say) table: 1F801F34, table:0D1C71AC. Every time I tested it the Serial number would always change never the same. The Best Code I could come up with trying to remove the other tables possibly is.
local AParts = {ChoosenMap:GetChildren()} local SParts = AParts if Player.TeamColor == BrickColor.new("Bright blue") then local Selecting = SParts[math.random(1,#SParts)] table.remove(Selecting,SParts) print (Selecting) end
The Problem with this code is with the table.remove It would always say "expected Number, got Table" and when I switched the placement of the items (SParts, Selecting) it would say "expected Table got Number". I'm almost about to give up on the whole thing cause this is one of the many functions I am trying to complete and this one is essential for it to work.
:GetChildren()
already returns an array of parts. No need to wrap it inside of another table.
Instead of
local AParts = {ChoosenMap:GetChildren()}
You can simply do
local AParts = ChoosenMap:GetChildren()
Also, for line 2
, keep in mind that you're just assigning SParts a reference to AParts. In other words, modifying (insert/remove) SParts will also modify AParts. This may or may not be what you intended.
Lastly, table.remove
(in its simplest form) requires a table and an index as its arguments, and returns the entry that was removed.
Instead of
local Selecting = SParts[math.random(1,#SParts)] table.remove(Selecting,SParts) print (Selecting)
You should instead do
local selectedIndex = math.random(#SParts) local Selecting = table.remove(SParts, selectedIndex) print (Selecting)
I've found the solution thanks to you guys, Thank you.
local ChoosenMap = script.Parent.Maps.Map1 game.Players.PlayerAdded:connect(function(Player) Part = ChoosenMap:GetChildren() for i,Parts in pairs(Part) do if Part.Troops == nil then script.Parent.Folder.Troops:Clone().Parent = Parts script.Parent.Folder.ClickDetector:Clone().Parent = Parts script.Parent.Folder.BillboardGui:Clone().Parent = Parts script.Parent.Folder.SurfaceGui:Clone().Parent = Parts script.Parent.Folder.Choosen:Clone().Parent = Parts Parts.BillboardGui.Enabled = true else return nil end if Player.TeamColor == BrickColor.new("Bright blue") then SelectSpawn() end end createTroops() end) function SelectSpawn () local AParts = ChoosenMap:GetChildren() local SelectedI = math.random(1,#AParts) local Selecting = table.remove(AParts, SelectedI) local Select = {Selecting} print(Select) for i , Selected in pairs(Select) do Selected:WaitForChild("SurfaceGui").Frame.BackgoundColor3 = Color3.new(255,0,0) end end
well, all that's needed now is finding a way I can find SurfaceGui. Thanks Guys.