Im using a module script and im kinda new to these stuff so i need some help
Im trying to make it when you give a petName to the module Function it gives you a number value back
Heres an example:
Pets.MultiplierValue = {
["Bear"] = 1.15;
["Fox"] = 1.17;
}
Pets.Multiplier = function(petName)
local multiplierValue
for i, v in pairs (Pets.MultiplierValue) do
-- If the PetName is Bear or Fox the multiplierValue will be set to their value from Above
end
return multiplierValue
end
I know this is pretty easy and stuff but i haven’t really ever studied i, v in pairs that much and sometimes linking up everything is confusing to me
It will seem like magic to you, but all you have to do is create an If statement. Honestly, you can try it yourself:
I don’t know about C++ and very, very advanced Lua, but it works. If I knew more about it I would explain it to you in more detail. Hope it’s enough, this is if you want to do this using the for i,v loop.
But I recommend the solution @Jaycbee05 gave you, it just searches the table for what you need and returns it (sounds weird, in other words it’s like you’re making workspace.part, you use the dot-operator. Same thing, only instead of a dot you use another way. You can learn more here, as these are actually dictionaries: Tables | Documentation - Roblox Creator Hub)
P.S.: And if anyone thought so, no, I didn’t copy everything from @Jaycbee05 , there are just limited ways to achieve this result (and i am using a translator and have bad wifi, so this comes late).