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

How to check if something is a part of a list you made in a script?

So I don't really know how to tell it but ill try my best, I just made something for a pet system that shows f.e.

if petname == "Giant Dog" then
PetRarity = "SECRET"

It only needs to be for pets that are rarity "secret"

but this takes ages to do for every single pet so I wanted to make a list where I add all petnames too so I can then do

if petname = part of the list

But I have no idea how it works, I have seen a script that has something that looks like the thing I need

local XP_RARITIES = {
	Common = 100,
	Rare = 200,
	Epic = 350,
	Legendary = 500,
	Robux = 500,
	Secret = 750,
}

Idk if this is it but it kinda shows the idea I put all pet names in and the check if petname is in the list

It would be amazing if someone could tell me how I make it and how to check if petname is in the list

Sry for my probably newbee question and sry for the probably bad explanation and post this is my first one.

1 comment

0

so like you can check if the petname is on a dictionary?

2 answers

✓ Accepted answer

You would use a module script. Module scripts are scripts that are meant for storing information. And, if you’d like to pull information out of a module script, you’d use the require function. Sorry if this is confusing but there’s a couple videos up on YouTube about module scripts if you need more help.

1 comment

0

ok ill take I look thx

if you're checking if a name is on a list you could do this:


local names = {
	["Giant Dog"] = {
		Xp = 100
		Rarity = "SECRET
	}
}

if names["Giant Dog"] then
	-- do something
end

you can add more articles to the list and add the if statement to some functions

3 comments

0

you would probably put the dictionary data in a modulescript^^^

0

I have a variable that has the name of the pet in it how do I check if hte name in that variable is in the list, because on this way I have to put the name of the pet if names["Giant Dog"] then

0

i dont get what ur saying

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