Problems with spin system

Everytime the player “spins” they keep ending up with last value in the table, even tho everything has a percentage.

			["Star Platnium"] = {
				["Percent"] = 1,
				["Skin"] = {}
			},
			["Whitesnake"] = {
				["Percent"] = 10,
				["Skin"] = {"Female"}
			},
			["The World"] = {
				["Percent"] = 1,
				["Skin"] = {"Female"}
			},
			["Kathastrophe"] = {
				["Percent"] = 10,
				["Skin"] = {}
			},
			["C-Moon"] = {
				["Percent"] = 10,
				["Skin"] = {}
			},
	local x = getWeights()
	local rand = R:NextNumber(0,x)
	for i,v in pairs(List) do
		rand -= v["Percent"]
		if rand < 0 then
			Selected = i
		end
	end

Because you’re not breaking your for loop after the condition is true.
Basically what happens is that when it ends up on 3rd choice, the rand is still a negative number and so the loop continues next, sees its still negative, then the selection is 4th, loop continues, does the same, its 5th selection.

if rand < 0 then
    Selected = i
    break
end
1 Like

ah my fault completely forgot abt doin that, thanks

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.