Is there a way to pick random values from a table that aren't numbers?

Maybe you could do something like:

table["guy" .. tostring(random)]

I used the guy1 naming stuff as an example, what about for just regular names?

Maybe you mean something like this:

local randomKey = keys[math.random(1, #keys)]
local randomVariable = myTable[randomKey]

Im not that great at scripting, what is the “key” referencing?

Here is what I have if this helps any more,

spinning script

As you can see from that, I have like 5 names that it circulates through, but its those same names every time. So what I am trying to do is make it go through any of the names in that clip to make it seem more genuine, if that makes sense.

Well you don’t have to do it like that but you can do it like this:

local randomNumber = math.random(1,#table)
local chosenValue = table[randomValue]

Basically, you have to convert the table into an array. Like this:

game.Players.PlayerAdded:Connect(function(Player)
	local Character = Player.Character or Player.CharacterAdded:Wait()
	local Humanoid = Character:WaitForChild("Humanoid")

	local CNRs = {
		--Ult

		guy1 = .05,
		guy2 = .05,
		guy3 = .05,
		guy4 = .05,
		guy5 = .05,
	}
	
	local keys = {}
	for k,v in pairs(CNRs) do
		table.insert(keys, k)
	end
	
	local DataFolder = Instance.new('Folder',Player)
	DataFolder.Name = "DataFolder"

	local Clan = Instance.new("StringValue", DataFolder)
	Clan.Name = "Clan"

	local Clan1 = Instance.new("NumberValue", DataFolder)
	Clan1.Name = "Spins"
	Clan.Value = math.random(1, #keys)
	print(Clan.Value)
	Clan1.Value = 5000
end)

If you need more information, you can check the following post, the OP explains in detail how it works.

I tested it so it should work.

I couldn’t find out a way to incorporate this in my own…

https://gyazo.com/6986e26cb615baf11e0a19eeeb68b7f7

While there is no error, it is just giving me numbers. Was there something I was supposed to change?

If you want to get the value instead of the index number, you can do the following:

game.Players.PlayerAdded:Connect(function(Player)
	local Character = Player.Character or Player.CharacterAdded:Wait()
	local Humanoid = Character:WaitForChild("Humanoid")

	local CNRs = {
		--Ult

		guy1 = .05,
		guy2 = .05,
		guy3 = .05,
		guy4 = .05,
		guy5 = .05,
	}
	
	local keys = {}
	for k,v in pairs(CNRs) do
		table.insert(keys, k)
	end
	
	local DataFolder = Instance.new('Folder',Player)
	DataFolder.Name = "DataFolder"

	local Clan = Instance.new("StringValue", DataFolder)
	Clan.Name = "Clan"

	local Clan1 = Instance.new("NumberValue", DataFolder)
	Clan1.Name = "Spins"
	Clan.Value = CNRs[math.random(1, #keys)]
	Clan1.Value = 5000
end)

Isn’t this the same script as the one above?

No, this line is different, now it assigns the value instead of the index.

Yeah this isn’t working for me, and I dont understand.

I’ve scrapped the changes and just put it back to what I had, Here are the three scripts I am using.

https://gyazo.com/d8a3f339cdc563fb6e89e29a19f3d20f

https://gyazo.com/ea6dd8ef0a7fed18c8c025bc776a1223

https://gyazo.com/a8f957d6339b2ca48d7648f4679edb24

This last one is the one I don’t want to use, but am using to make the spin effect.

Hello, couldn’t you do something like this?

local function getSizeOfDict(dict)
    local count = 0
    for _, _ in pairs(dict)
        count += 1
    end
end

local function getRandom(dict)
    local random = math.random(1, getSizeOfDict(CNRs)]
    local chosen = ""
    for index, _ in pairs(dict) do
        if index == dict[random] then
            chosen = dict[random]
            break
        end
    end
    return chosen
end

for c = 1, 15 do
    displayYourName(getRandom(CNRs))
end

For the displayYourName part, what do I change to make it work correctly?

1 Like

Just change text, whatever it is: textLabel.Text = getRandom(CNRs)

There is no error but it is not spinning, here is the code

local CNRs = {
	--Ult

	Freecss = .05,
	Kurta = .05,
	Zoldyck  = .05,
	Meruem = .05,
	Netero = .05,

	-- Legendary

	Lucilfer = 1,
	Neferpitou = 1,
	Kite = 1,
	Morow = 1,
	Portor = 1,
	Gigante = 1,
	Pyon = 1,

	--Epic

	Uvogin = 3,
	Machi = 3,
	Hazama = 3,
	Shizuku = 3,
	Shalnark = 3,
	Pakunoda = 3,
	Bonolenov = 3,
	Krueger = 3,
	Magcub = 3,
	Mackernasey = 3,
	Nana = 3,

	--Rare

	Knov = 15,
	Hill = 15,
	Yorkshire = 15,
	Paradinight = 15,
	Kobayakawa = 15,
	Bine = 15,
	McMahon = 15,

	--Uncommon

	Siberia = 20,
	Pokkle = 20,
	Hanzo = 20,
	Buhara = 20,
	Baise = 20,
	Bodoro = 20,
	Geretta = 20,

	--Common

	Tsezguerra = 70,
	Agon = 70,
	Amori = 70,
	Umori = 70,
	Imori = 70,
	Tonpa = 70,
	Bourbon = 70,
	Ponzu = 70,
	Kyu = 70,
	Todo = 70,
	Morel = 70,
	Mercer = 70,
	Goz = 70,
}

local function getSizeOfDict(dict)
	local count = 0
	for _, _ in pairs(dict) do
		count += 1
	end
end

local function getRandom(dict)	local random = math.random(1, getSizeOfDict(CNRs))
		local chosen = ""
for index, _ in pairs(dict) do
	if index == dict[random] then
		chosen = dict[random]
		break
	end
end
return chosen
end

for c = 1, 15 do
	script.Parent.Parent.Clan.Text = getRandom(CNRs)
end

Just replace index == dict[random] with index == random

I still need help on this when you are available.

So anyone can get the solution:

local CNRs = {
    --Ult

    Freecss = .05,
    Kurta = .05,
    Zoldyck  = .05,
    Meruem = .05,
    Netero = .05,

    -- Legendary

    Lucilfer = 1,
    Neferpitou = 1,
    Kite = 1,
    Morow = 1,
    Portor = 1,
    Gigante = 1,
    Pyon = 1,

    --Epic

    Uvogin = 3,
    Machi = 3,
    Hazama = 3,
    Shizuku = 3,
    Shalnark = 3,
    Pakunoda = 3,
    Bonolenov = 3,
    Krueger = 3,
    Magcub = 3,
    Mackernasey = 3,
    Nana = 3,

    --Rare

    Knov = 15,
    Hill = 15,
    Yorkshire = 15,
    Paradinight = 15,
    Kobayakawa = 15,
    Bine = 15,
    McMahon = 15,

    --Uncommon

    Siberia = 20,
    Pokkle = 20,
    Hanzo = 20,
    Buhara = 20,
    Baise = 20,
    Bodoro = 20,
    Geretta = 20,

    --Common

    Tsezguerra = 70,
    Agon = 70,
    Amori = 70,
    Umori = 70,
    Imori = 70,
    Tonpa = 70,
    Bourbon = 70,
    Ponzu = 70,
    Kyu = 70,
    Todo = 70,
    Morel = 70,
    Mercer = 70,
    Goz = 70,
}

local function getSizeOfDict(dict)
    local count = 0
    for _, _ in pairs(dict) do
        count = count + 1
    end
    return count
end
local function getRandom(dict)
    local random = math.random(1, getSizeOfDict(dict))
    local count = 0
    for name, _ in pairs(dict) do
        if count == random then
            return name
        end
        count += 1
    end
end

script.Parent.MouseButton1Click:Connect(function()
    for c = 1, 15 do
        script.Parent.Parent.Clan.Text = getRandom(CNRs)
        task.wait(0.06)    
    end
end)

This is probably the simplest way you can do it.

local RandomValue = CNRs[math.random(1, #CNRs)]

This line will always work as long as CNRs has at least one item.

This will only work on arrays, not dicts as the indexes aren’t numbers but string.