Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Check if PetName is in ModuleScript/Dictionary?

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

✓ Accepted answer

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

1 comment

0

Thx A lot it worked

This discussion is preserved as it was. New answers, comments, and votes are closed.