How can I make this efficient without/with using math.random()?
local colors = require(script:WaitForChild("Color_Rarity"))
local Gui = script.Parent
local ColorButton = Gui.ColorButton
local function ChooseWhichColorCommon()
local CommonRandom = math.random(1, 3)
ColorButton.BackgroundColor3 = workspace.ColorChanger.Color
if CommonRandom == 1 then
colors.ChooseRandomCommonColor('Red')
end
if CommonRandom == 2 then
colors.ChooseRandomCommonColor('Blue')
end
if CommonRandom == 3 then
colors.ChooseRandomCommonColor('Green')
end
end
local function MouseClicked()
return ChooseWhichColorCommon()
end
ColorButton.MouseButton1Down:Connect(MouseClicked)
It says that, âPlayers.Cxdious.PlayerGui.ColorGui.ColorChanger:14: invalid argument #2 to ârandomâ (interval is empty)â - Line 14
local colors = require(script:WaitForChild("Color_Rarity"))
local ColorChanger = workspace:WaitForChild("ColorChanger")
local Gui = script.Parent
local ColorButton = Gui.ColorButton
local CommonColors = {
colors.ChooseRandomCommonColor("Red");
colors.ChooseRandomCommonColor("Blue");
colors.ChooseRandomCommonColor("Green")
}
local function ChooseWhichColorCommon()
ColorButton.BackgroundColor3 = workspace.ColorChanger.Color
local color = CommonColors[math.random(1, #CommonColors)]
ColorChanger.BrickColor = BrickColor.new(color)
return color
end
local function MouseClicked()
return ChooseWhichColorCommon()
end
ColorButton.MouseButton1Down:Connect(MouseClicked)
local ColorButton = script.Parent.Parent.ColorButton
local RS = game:GetService("ReplicatedStorage")
local PointEvent = RS.Color
local CommonColors = {
['Red'] = {
['Color'] = BrickColor.new("Bright red")
},
['Green'] = {
['Color'] = BrickColor.new("Bright green")
},
['Blue'] = {
['Color'] = BrickColor.new("Bright blue")
}
}
function CommonColors.ChooseRandomCommonColor(color)
local function rando()
local random = math.random(1,4)
if CommonColors[color] then
if random == 2 then
workspace:WaitForChild("ColorChanger").BrickColor = CommonColors[color].Color
PointEvent:FireServer()
end
end
end
ColorButton.MouseButton1Down:Connect(rando)
print(workspace.ColorChanger.BrickColor)
end
return CommonColors
function CommonColors.ChooseRandomCommonColor(color)
local colours = CommonColors.data
local random = math.random(1, #colours)
local final = random[math.random(1, #random)]
return final
end
the only issue is that I have no idea what the remote event does.
The code above chooses one of the colours from the rom.
edit -lmk If you need any explaining on what I did.
Now it changed to the color intended. Thank you! But, itâs going to be annoying to say but, now it says âPlayers.Cxdious.PlayerGui.ColorGui.ColorChanger:13: invalid argument #2 to ârandomâ (interval is empty)â