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 9 years ago
01local Eye = {[1]= "Left Eye", [2]= "Right Eye"}
02local 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"}
03local Nose = {[1]= "Nose"}
04script.Parent.Target.Changed:connect(function()
05if script.Parent.Target.Value == Eye[1] or Eye[2] then
06    script.Parent.EyeColors.Visible = true
07    script.Parent.FurColors.Visible = false
08    script.Parent.NoseColors.Visible = false
09    print(script.Parent.EyeColors.Name)
10elseif 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
11    script.Parent.FurColor.Visible = true
12    script.Parent.EyeColors.Visible = false
13    script.Parent.NoseColors.Visible = false
14    print(script.Parent.FurColors.Name)
15elseif script.Parent.Target.Value == Nose[1] then
View all 22 lines...

1 answer

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

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

1elseif 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.

1elseif 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.

1function check(table, lookFor)
2    for i, v in pairs(table) do
3        if lookFor == v then
4            return true
5        end
6    end
7end

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

1local dictionary = { ["a"] = true, ["b"] = true }
2 
3if 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 — 9y
Ad

Answer this question