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 3 years ago
Edited 3 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

local Rarities = {

    ["Giant Dog"] = "SECRET"
    ["Giant Cat"] = "SECRET"
}

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:

Local name = PetName -- so the in name is the name of the pet that I need to find in the modulescript/dictionary
if Rarities.FindFirstChild(rName) ~= nil then
PetRarity.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
3 years ago
Edited 3 years ago

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

local Secret = Rarities[PetName]

if (Secret) then

    PetRarity.Text = Secret

[] is used for indexing the list

local Table = {

    'cat'
    ['key'] = 50,
    'cat2'
    [4] = true,
}

Table[1] -- cat
Table['key']  -- 50
Table[2] -- cat2
Table[4] -- true

Table[1] = 'giraffe'
Table[2] = nil

Table[1] -- giraffe

Table[2] -- nil
0
Thx A lot it worked jeboysisi 26 — 3y
Ad

Answer this question