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

Why does EyeColors only show?

Asked by 8 years ago
local Eye = {[1]= "Left Eye", [2]= "Right Eye"}
local Fur = {[1]="F-L Leg", [2]="F-R Leg", [3]= "F-Left Paw", [4]= "F-R Paw", [5]="B-L Leg",[6]="B-R Leg", [7]="B-L Paw", [8]="B-R Paw", [9]="Head",[10]="Inner Ears",[11]="Outer Ear L",[12]="Outer Ear R",[13]="Muzzle Bottom",[14]="Muzzle Top",[15]="Neck",[16]="Tail Top",[17]="Tail Bottom"}
local Nose = {[1]= "Nose"}
script.Parent.Target.Changed:connect(function()
if script.Parent.Target.Value == Eye[1] or Eye[2] then
    script.Parent.EyeColors.Visible = true
    script.Parent.FurColors.Visible = false
    script.Parent.NoseColors.Visible = false
    print(script.Parent.EyeColors.Name)
elseif script.Parent.Target.Value == Fur[1] or Fur[2] or Fur[3] or Fur[4] or Fur[5] or Fur[6] or Fur[7] or Fur[8] or Fur[9] or Fur[10] or Fur[11] or Fur[12] or Fur[13] or Fur[14] or Fur[15] or Fur[16] or Fur[17] then
    script.Parent.FurColor.Visible = true
    script.Parent.EyeColors.Visible = false
    script.Parent.NoseColors.Visible = false
    print(script.Parent.FurColors.Name)
elseif script.Parent.Target.Value == Nose[1] then
    script.Parent.NoseColors.Visible = true
    script.Parent.EyeColors.Visible = false
    script.Parent.FurColors.Visible = false
    print(script.Parent.NoseColors.Name)
end
end)
--This is my first time trying at using tables, if I'm using them wrong, let me know! Thanks!

1 answer

Log in to vote
1
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
8 years ago

I didn't read through everything, but this line is definitely a problem...

elseif script.Parent.Target.Value == Fur[1] or Fur[2] or Fur[3] or Fur[4] or Fur[5] or Fur[6] or Fur[7] or Fur[8] or Fur[9] or Fur[10] or Fur[11] or Fur[12] or Fur[13] or Fur[14] or Fur[15] or Fur[16] or Fur[17] then

Alright, first of all, EW!

Second of all, it won't work. or separates two different, unique conditions, so you have to state two unique conditions. You have this problem on line 5 as well.

elseif script.Parent.Target.Value == Fur[1] or script.Parent.Target.Value == Fur[2]

But don't do this, because it will make the code even more OCD-murdering. You have two options to clean this up.


First is we use a for loop to go through the entire table and see if we have a match. It would be best to put it in a function.

function check(table, lookFor)
    for i, v in pairs(table) do
        if lookFor == v then
            return true
        end
    end
end

Your second options is to use a dictionary, making the value true and the key whatever you want.

local dictionary = { ["a"] = true, ["b"] = true }

if dictionary["a"] then --since dictionary["a"] equals true, the condition will pass
0
That's a decent idea, with the Dictionary that is. I was looking at it like: "Okay, that's pretty interesting, but I want to see how tables work." Thanks! Vingam_Securis 213 — 8y
Ad

Answer this question