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

How do I make this script print the item name?

So I have this script that selects a random item in the pets table but it prints the amount of characters the name contains rather than the actual name. An example of this would be "Selected 5". I am wondering how to change this to make it print the item name. An example would be "Selected Fire Sword".

local Pets = {
	rarities = {0.6,0.4};
	pets = {
		{
			name="Part";
			rarity="Rare";
		};	
		{
			name="Part2";
			rarity="Legendary";
		};	
	};
};

local totalweight = 0

for _,v in ipairs(Pets.rarities) do
	totalweight = totalweight + v
end

local at = math.random() * totalweight

for i,v in pairs(Pets.rarities) do
    if at < v then
        print(Pets.pets[i] .. " has been chosen!")
        break
    end
    at = at - v
end

1 answer

✓ Accepted answer

This seems like the obvious solution:

print(Pets.pets[i] .. " has been chosen!")

Change to

print(Pets.pets[i].name .. " has been chosen!")

2 comments

0

It still prints the amount of characters of the name

1

nvm for some reason it doesn't like if you do #Pets so I had to do Pets thanks alot!

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