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

Why do the strings in my table return a number value?

I can't figure out how to fix this. Basically, i'm experimenting by making a basic mha game, and i'm working on a way to switch quirks. whenever I run this script though, I get this error:

Players.Hindile.PlayerGui.quirkSpin.Main.Spin.TextButton.LocalScript:28: attempt to index a number value

This is my code.

local quirks = {
{Quirk = "Erasure", Rarity = "Legendary", Chances = 0.05},
{Quirk = "WarpGate", Rarity = "Rare", Chances = 0.15}
}
local ok = game.Players.LocalPlayer.PlayerGui.quirkSpin.Main.OK
local main = game.Players.LocalPlayer.PlayerGui.quirkSpin.Main
local white = game.Players.LocalPlayer.PlayerGui.quirkSpin.Main.White
local spin = game.Players.LocalPlayer.PlayerGui.quirkSpin.Main.Spin
local amountofspins = 20
local spintime = 5

function insert()
	for i = 1,#quirks do
		local times = quirks[i].Chances * 100
		repeat
			table.insert(quirks,quirks[i])
			times = times - 1
			wait()
		until times == 0
		wait()
	end
end

insert()

spin.TextButton.MouseButton1Click:Connect(function()
		repeat
			white.QuirkDecision.Text = math.random(1,#quirks).Quirk
			spintime = spintime - .2
			wait(.2)
		until spintime == 0
		
		if spintime == 0 then
			white.QuirkDecision.Text = math.random(1,#quirks).Quirk
		end
end)

1 answer

✓ Accepted answer

You almost had it! Replace line 28 and line 34 with:

white.QuirkDecision.Text = quirks[math.random(1,#quirks)].Quirk

Since you are accessing a key of a dictionary, you still need the table dictionary!

1 comment

0

It works perfectly now. Thanks!

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