Gives random points

Hello! I have this color rarity system. It sometimes add random points. For example: If I get a red, it sometimes adds 2 or 4 points even though it’s not one of the colors in the table. I need help

local ColorButton = script.Parent.Parent.ColorButton
local RS = game:GetService("ReplicatedStorage")
local PointEvent = RS.Color
-- [Multiplier]
local Common = 1
local Rare = 2
local Epic = 4
local Legendary = 10
local Mythical = 30
local Ultra = 50
local Unique = 80
local Secrets = 500
------

local CommonColors = {
	['Red'] = {
		['Color'] = BrickColor.new("Bright red")
		
	},
	
	['Green'] = {
		['Color'] = BrickColor.new("Bright green")
		
	},
	
	['Blue'] = {
		['Color'] = BrickColor.new("Bright blue")
		
	}
	
}

local RareColors = {
	['Orange'] = {
		['Color'] = BrickColor.new("Bright orange")
		
	},
	
	['Yellow'] = {
		['Color'] = BrickColor.new("Bright yellow")
		
	}
	
}

local EpicColors = {
	['Brown'] = {
		['Color'] = BrickColor.new("Brown")
		
	},
	
	['Olive'] = {
		['Color'] = BrickColor.new("Olive")
		
	},
	
	['Mulberry'] = {
		['Color'] = BrickColor.new("Mulberry")
		
	}
	
}

local Module = {}

function Module.ChooseRandomCommonColor(color)
	local function rando()
		local Chance = 1
		local random = math.random(1,80)
		local Points = 0
		if CommonColors[color] then
	
			if random <= 20 and random > Chance then
				Points = Common
				workspace:WaitForChild("ColorChanger").BrickColor = CommonColors[color].Color
				PointEvent:FireServer(Points)
				print(random.." Common, "..tostring(workspace.ColorChanger.BrickColor))
			end
	 
		end
	end

	ColorButton.MouseButton1Down:Connect(rando)
end

function Module.ChooseRandomRareColor(color)
	local function rando()
		local Chance = 30
		local Points = 0
		local random = math.random(30,150)
		if RareColors[color] then

			if random <= 40 and random > Chance then
				Points = Rare
				workspace:WaitForChild("ColorChanger").BrickColor = RareColors[color].Color
				PointEvent:FireServer(Points)
				print(random.." Rare, "..tostring(workspace.ColorChanger.BrickColor))
			end

		end
	end

	ColorButton.MouseButton1Down:Connect(rando)
end

function Module.ChooseRandomEpicColor(color)
	local function rando()
		local Points = 0
		local Chance = 50
		local random = math.random(50,200)
		if EpicColors[color] then

			if random <= 55 and random > Chance then
				Points = Epic
				workspace:WaitForChild("ColorChanger").BrickColor = EpicColors[color].Color
				PointEvent:FireServer(Points)
				print(random.." Epic, "..tostring(workspace.ColorChanger.BrickColor))
			end

		end
	end

	ColorButton.MouseButton1Down:Connect(rando)
end

return Module


Edit: It doubles rolls for some weird reason. I added print

1 Like

you mentioned that random points are sometimes added even when the color is not in the table. this issue might be due to the random numbers you’re generating, which do not always match the condition for assigning points.

– … (your code for color tables and constants)

function Module.ChooseRandomCommonColor(color)
local function rando()
local random = math.random(1, 100)
local Points = 0
if CommonColors[color] then
if random <= 20 then – adjust this probability based on desired rarity
Points = Common
workspace:WaitForChild(“ColorChanger”).BrickColor = CommonColors[color].Color
PointEvent:FireServer(Points)
end
end
end

ColorButton.MouseButton1Down:Connect(rando)
print(workspace.ColorChanger.BrickColor)

end

– … (repeat similar modifications for the other rarities)

this should work, but since i don’t know exactly what is supposed to happen i’m not 100% certain.
(also i apologize for the crappy code formatting, i’ve never posted help before)

3 Likes

I’ll try this tomorrow as I am getting ready for bed

1 Like

Didn’t work but it fixed most of the problems but still gives random points

local ColorButton = script.Parent.Parent.ColorButton
local RS = game:GetService("ReplicatedStorage")
local PointEvent = RS.Color
-- [Multiplier]
local Common = 1
local Rare = 2
local Epic = 4
local Legendary = 10
local Mythical = 30
local Ultra = 50
local Unique = 80
local Secrets = 500
------

local CommonColors = {
	['Red'] = {
		['Color'] = BrickColor.new("Bright red")
		
	},
	
	['Green'] = {
		['Color'] = BrickColor.new("Bright green")
		
	},
	
	['Blue'] = {
		['Color'] = BrickColor.new("Bright blue")
		
	}
	
}

local RareColors = {
	['Orange'] = {
		['Color'] = BrickColor.new("Bright orange")
		
	},
	
	['Yellow'] = {
		['Color'] = BrickColor.new("Bright yellow")
		
	}
	
}

local EpicColors = {
	['Brown'] = {
		['Color'] = BrickColor.new("Brown")
		
	},
	
	['Olive'] = {
		['Color'] = BrickColor.new("Olive")
		
	},
	
	['Mulberry'] = {
		['Color'] = BrickColor.new("Mulberry")
		
	}
	
}

local Module = {}

function Module.ChooseRandomCommonColor(color)
	local function rando()
		local Chance = 1
		local random = math.random(1,80)
		local Points = 0
		if CommonColors[color] then
	
			if random <= 20 and random > Chance then
				Points = Common
				workspace:WaitForChild("ColorChanger").BrickColor = CommonColors[color].Color
				PointEvent:FireServer(Points)
			end
	 
		end
	end

	ColorButton.MouseButton1Down:Connect(rando)
	print(workspace.ColorChanger.BrickColor)
end

function Module.ChooseRandomRareColor(color)
	local function rando()
		local Chance = 30
		local Points = 0
		local random = math.random(30,150)
		if RareColors[color] then

			if random <= 40 and random > Chance then
				Points = Rare
				workspace:WaitForChild("ColorChanger").BrickColor = RareColors[color].Color
				PointEvent:FireServer(Points)
			end

		end
	end

	ColorButton.MouseButton1Down:Connect(rando)
	print(workspace.ColorChanger.BrickColor)
end

function Module.ChooseRandomEpicColor(color)
	local function rando()
		local Points = 0
		local Chance = 50
		local random = math.random(50,200)
		if EpicColors[color] then

			if random <= 55 and random > Chance then
				Points = Epic
				workspace:WaitForChild("ColorChanger").BrickColor = EpicColors[color].Color
					PointEvent:FireServer(Points)
			end

		end
	end

	ColorButton.MouseButton1Down:Connect(rando)
	print(workspace.ColorChanger.BrickColor)
end

return Module

Fixed it!!!

local ColorButton = script.Parent.Parent.ColorButton
local RS = game:GetService("ReplicatedStorage")
local PointEvent = RS.Color
local ROLLS = 0

-- [Multiplier]
local Common = 1
local Rare = 2
local Epic = 4
local Legendary = 10
local Mythical = 30
local Ultra = 50
local Unique = 80
local Secrets = 500
------

local CommonColors = {
	['Red'] = {
		['Color'] = BrickColor.new("Bright red")

	},

	['Green'] = {
		['Color'] = BrickColor.new("Bright green")

	},

	['Blue'] = {
		['Color'] = BrickColor.new("Bright blue")

	}

}

local RareColors = {
	['Orange'] = {
		['Color'] = BrickColor.new("Bright orange")

	},

	['Yellow'] = {
		['Color'] = BrickColor.new("Bright yellow")

	}

}

local EpicColors = {
	['Brown'] = {
		['Color'] = BrickColor.new("Brown")

	},

	['Olive'] = {
		['Color'] = BrickColor.new("Olive")

	},

	['Mulberry'] = {
		['Color'] = BrickColor.new("Mulberry")

	}

}

local Module = {}

function Module.ChooseRandomCommonColor(color)
	local function rando()
		local Chance = 1
		local random = math.random(1,80)
		local Points = 0
		if CommonColors[color] then
			if ROLLS == 0 then
				if random <= 20 and random > Chance then
					ROLLS += 1
					Points = Common
					workspace:WaitForChild("ColorChanger").BrickColor = CommonColors[color].Color
					PointEvent:FireServer(Points)
					
					print(random.." Common, "..tostring(workspace.ColorChanger.BrickColor))
				end
				wait()
			end

		end
	end

	ColorButton.MouseButton1Down:Connect(rando)
end

function Module.ChooseRandomRareColor(color)
	local function rando()
		local Chance = 30
		local Points = 0
		local random = math.random(30,150)
		if RareColors[color] then
			if ROLLS == 0 then
				if random <= 40 and random > Chance then
					ROLLS += 1
					Points = Rare
					workspace:WaitForChild("ColorChanger").BrickColor = RareColors[color].Color
					PointEvent:FireServer(Points)
					
					print(random.." Rare, "..tostring(workspace.ColorChanger.BrickColor))
				end
				wait(.3)
				ROLLS = 0
			end

		end
	end

	ColorButton.MouseButton1Down:Connect(rando)
end

function Module.ChooseRandomEpicColor(color)
	local function rando()
		local Points = 0
		local Chance = 50
		local random = math.random(50,200)
		if EpicColors[color] then
			if ROLLS == 0 then
				if random <= 55 and random > Chance then
					ROLLS += 1
					Points = Epic
					workspace:WaitForChild("ColorChanger").BrickColor = EpicColors[color].Color
					PointEvent:FireServer(Points)
					
					print(random.." Epic, "..tostring(workspace.ColorChanger.BrickColor))
				end
				wait(.3)
				ROLLS = 0
			end

		end
	end

	ColorButton.MouseButton1Down:Connect(rando)
end

return Module

that’s great :+1:

character requirement, ignore this

1 Like

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