Warning: very rookie dev; ugly code ahead:
I’m working on a puzzle game with a large group of colored blocks that are either red, orange, yellow, green, blue, magenta, gray or black.
I periodically generate a player block that is one of these colors. The large group of blocks is constantly changing and may be any combination of these colors and may not include certain colors at any given time. The player block must be one of the remaining colors.
I need to check the large group of blocks on the server, then have a table returned to the client that looks like this, but only includes the colors that were found remaining in the group.
local Color = {BrickColor.new("Really red"), BrickColor.new("Neon orange"),BrickColor.new("New Yeller"), BrickColor.new("Lime green"), BrickColor.new("Really blue"), BrickColor.new("Magenta"), BrickColor.new("Cloudy grey"), BrickColor.new("Really black")}
I have this code that, when pinged by the client, loops through all game blocks and returns which colors are still present back to the server. (I know how poor this looks, again rookie here…)
ReplicatedStorage.RemEvRemColorCheck.OnServerEvent:Connect(function(player,Set)
local R = false
local O = false
local Y = false
local G = false
local B = false
local M = false
local Gr = false
local Bl = false
for i, part in pairs(Set.Parts:GetChildren()) do
if part.BrickColor == BrickColor.new("Really red") then R = true end
if part.BrickColor == BrickColor.new("Neon orange") then O = true end
if part.BrickColor == BrickColor.new("New Yeller") then Y = true end
if part.BrickColor == BrickColor.new("Lime green") then G = true end
if part.BrickColor == BrickColor.new("Really blue") then B = true end
if part.BrickColor == BrickColor.new("Magenta") then M = true end
if part.BrickColor == BrickColor.new("Cloudy grey") then Gr = true end
if part.BrickColor == BrickColor.new("Really black") then Bl = true end
end
game.ReplicatedStorage.RemEvRemColorCheck:FireClient(player,R,O,Y,G,B,M,Gr,Bl) -- TO SERVER - fires after loop
end)
Question: How can I translate my returned data (true / false for each color), into a table like this?
local Color = {BrickColor.new("Really red"), BrickColor.new("Neon orange"),BrickColor.new("New Yeller"), BrickColor.new("Lime green"), BrickColor.new("Really blue"), BrickColor.new("Magenta"), BrickColor.new("Cloudy grey"), BrickColor.new("Really black")}
local function SpawnNextPart() -- Function to bring a Part into the Next-Part waiting spot
if PartQueued == false then
PartQueued = true
local NextPart = Part:Clone()
NextPart.Position = Set.PNextPart.Position
NextPart.BrickColor = Colors[math.random(#Colors)]
end
end
Appreciate any help.