If Statement not working

Alright so I’m basically making a game like Color block and for my round, I have a table containing all my colors, the server picks one radomly and then sets all pats that are not that color in the table to 0 transparency and it sets CanCollide to false

However it does not seem to be working I’ve spent some time debugging it has nothing do with my bindable event that I have set up.

here’s my code:

Thanks In advance!

Do any of the print statements print anything?

Nope.
Ignore them I used them for debugging and thats how I know its the if statement thats not working

Try adding a print statement for the pairs loop, and see what it returns.

Already did, the pairs loop works. It’s the if statment that won’t work

Maybe because you are comparing an object for a number
Picked return a random number between 1 and the number of children of ColorTable not the object

Try this for the first if statement:

if v == ColorTable[Picked] or ... then
       print("work")
end

And for the other if statwment I need to know what Instance is this like is it a Part or Color3Value?

You are comparing an instance to a number. So instead of doing

v == Picked

DO.

i == Picked

i think? Or is colortable a table like its not gotten by using “:GetChildren”

Hmm…

local ColorBind = game.ReplicatedStorage.ColorBind
local Colors = game.Workspace.Colors

ColorBind.Event:Connect(function()
    local ColorTable = Colors:GetChildren()
    local Picked = math.random(1, #ColorTable)
    local ChosenColor = ColorTable[Picked]

    print("Chosen Color is " .. ChosenColor.Name)
    print(ChosenColor.BrickColor)

    for _, v in pairs(ColorTable) do
        if v ~= ChosenColor then
            print("Work")

            local Trans = v:GetAttribute("Transparency")
            Trans = 0
            v:SetAttribute("Transparency", Trans)

            local CanCollide = v:GetAttribute("CanCollide")
            CanCollide = 0
            v:SetAttribute("CanCollide", CanCollide)
        end
    end
end)

wdym by comparing an object for a number? I’m a bit new to scripting so I’m still making some logical mistakes. Could you explain what you mean?

Also I should carify what the if statement is checking, basically it selects a random part that has a certain color my idea was for my if statment to loop through the table and check whether a part is the picked part or if it is the same color as the picked part.

Basically objects are instances and instances are object. An object is something that uses instance.new or anything found in the explorer.
Comparing a number to and object isnt possible because for example
you cant compare a pen and a pencil sharpener because both are different from apart. Another explaination

“this is a string” > 9
that text above isnt possible because you are comparing text(in our case its an instance) next to a number

So how would I turn my number back into an Instance?

the ChosenColor is already doing that why not using it instead of using Picked in the if statement

There is various ways to achieve that but i dont really know what “ColorTable” so i dont know what you are trying to achieve. But like is said
image
Try replacing the two “v” to an “i” and see if that achieves your goal

Yea I noticed that and changed it