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

Is there a way to make math.random more random?

So I have a script when you click a text button, it changes color randomly. But when I need more colors when I click it because when I do click it gives me 8 different colors.

repeat wait() until game.Players.LocalPlayer.Character
repeat wait() until game.Players.LocalPlayer.Character.Torso:WaitForChild("BillboardGui")

script.Parent.MouseButton1Down:connect(function()
	script.Parent.TextColor3 = Color3.new(math.random(0,1),math.random(0,1),math.random(0,1))
	game.Players.LocalPlayer.Character.Torso.SurfaceGui.TextLabel.TextColor3 = script.Parent.TextColor3
	game.Players.LocalPlayer.Character.Torso.BillboardGui.TextLabel.TextColor3 = script.Parent.TextColor3
end)

Is there a way to make it choose more random?

1 answer

✓ Accepted answer

With two arguments, math.random will only return integers between the first and second.

So, math.random(0, 1) will only give you either 0 or 1.

If you want a random real number between 0 and 1, you would use math.random() with no arguments. (Note that this includes 0 but does not include 1)

	Color3.new( math.random(), math.random(), math.random() )

Note: This isn't "more random." It is just as random, it just has more possible values.


You should probably use variables for the local player and their character. That will shorten the script significantly:

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:wait()
	-- neat trick for getting the player's character

local bill = character:WaitForChild("Torso"):WaitForChild("BillboardGui")
-- Don't just wait, save it to a variable! Saves 

script.Parent.MouseButton1Down:connect(function()
	script.Parent.TextColor3 =
		Color3.new(math.random(), math.random(), math.random())
	character.Torso.SurfaceGui.TextLabel.TextColor3 =
		script.Parent.TextColor3
	bill.TextLabel.TextColor3 = script.Parent.TextColor3
end)

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