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

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

Asked by 3 years ago
Edited 3 years ago

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.

0
so like you can check if the petname is on a dictionary? NeonPandaEyes331 21 — 3y

2 answers

Log in to vote
0
Answered by 3 years ago

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.

0
ok ill take I look thx jeboysisi 26 — 3y
Ad
Log in to vote
0
Answered by 3 years ago

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

0
you would probably put the dictionary data in a modulescript^^^ NeonPandaEyes331 21 — 3y
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 jeboysisi 26 — 3y
0
i dont get what ur saying NeonPandaEyes331 21 — 3y

Answer this question