Random orientation of dice

I would like to make a dice game and each round I want the dice to respawn in that position ( I already did that ) but with a random orientation, how do I do this?

This is the code I currently have, how do I implement a random orientation?

local dice1 = game.Workspace:FindFirstChild("Dice1")
local dice2 = game.Workspace:FindFirstChild("Dice2")

local victorysound = game.Workspace:WaitForChild("SoundEffects"):WaitForChild("victory")

local startgame = true

while true do
	if startgame == true then
		startgame = false
		if dice1.Anchored == true and dice2.Anchored == true then
			dice1.Anchored = false
			dice2.Anchored = false
		end
		wait(7)
		dice1.Anchored = true
		dice2.Anchored = true
		dice1.Position = Vector3.new(4.55, 40.098, -45.091)
		dice2.Position = Vector3.new(-34.66, 40.098, -23.891)
	end
	startgame = true
end
1 Like

You can multiply the dice’s CFrame by a random angle.

Code:

local dice = workspace.myDice
dice.CFrame *= CFrame.Angles(math.rad(20), math.rad(90), math.rad(45))

To get random numbers, you can use math.random.

2 Likes

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