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

Check if PetName is in ModuleScript/Dictionary?

Asked by 4 years ago
Edited 4 years ago

I made I post earlier today asking how to make a List in a script. After some help and some yt videos I now know that I can use a module script or a dictionary

now I got the next problem, this is an example of the dictionary I used

1local Rarities = {
2 
3    ["Giant Dog"] = "SECRET"
4    ["Giant Cat"] = "SECRET"
5}

now let's say I have a pet inventory with 3 pets a "Giant Dog" a "Giant Cat" and a normal "Dog" dor example I want to make a script that checks if the name of the pet is "Giant Dog" or "Giant Cat" then it shows a SECRET tag on it here an example script of what I tried:

1Local name = PetName -- so the in name is the name of the pet that I need to find in the modulescript/dictionary
2if Rarities.FindFirstChild(rName) ~= nil then
3PetRarity.Text = Rarities.FindFirstChild(name)

well ofcourse this didn't work

So I want to check if the name of the pet is in the Dictionary/module script but idk how

1 answer

Log in to vote
0
Answered by
imKirda 4491 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

FindFirstChild does not exist on tables, this is why you index them, in your case you would do

1local Secret = Rarities[PetName]
2 
3if (Secret) then
4 
5    PetRarity.Text = Secret

[] is used for indexing the list

01local Table = {
02 
03    'cat'
04    ['key'] = 50,
05    'cat2'
06    [4] = true,
07}
08 
09Table[1] -- cat
10Table['key']  -- 50
11Table[2] -- cat2
12Table[4] -- true
13 
14Table[1] = 'giraffe'
15Table[2] = nil
16 
17Table[1] -- giraffe
18 
19Table[2] -- nil
0
Thx A lot it worked jeboysisi 26 — 4y
Ad

Answer this question