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

Why does the Position and Position functions don't work?

It's ment to be a little dice game triggerd from a button but there are some functions such as GeneratePosition():20 and GenerateOrientation():32 that gives me errors. here is the code:

--Variables
local Button = game.Workspace.Button
local ClickDetector = Button.ClickDetector
local Dice1 = game.Workspace.Dices.Dice1
local Dice2 = game.Workspace.Dices.Dice2

--Functions
	--Button
function ButtonPress()
	Button.Position = Vector3.new(32.243, 10.758, 20.960)
	Button.Material = ("Neon")
end

function ButtonRelease()
	Button.Position = Vector3.new(32.243, 10.758, 20.441)
	Button.Material = ("Plastic")
end

	--Dices
function GeneratePosition()
	local X1 = math.random(-17, -19)
	local Y1 = math.random(42, 44)
	local Z1 = math.random(-29, -31)
	local X2 = math.random(-13, -15)
	local Y2 = math.random(36, 38)
	local Z2 = math.random(-25, -27)
	
	Dice1.Position = Vector3.new(X1, Y2, Z1)
	Dice2.Position = Vector3.new(X2, Y2, Z2)
end

function GenerateOrientation()
	Dice1.Orientation.X = math.random(0, 90)
	Dice1.Orientation.Y = math.random(0, 90)
	Dice1.Orientation.Z = math.random(0, 90)
	
	Dice1.Orientation.X = math.random(0, 90)
	Dice1.Orientation.Y = math.random(0, 90)
	Dice1.Orientation.Z = math.random(0, 90)
end

function DicesAnchoredFalse()
	Dice1.Anchored = false
	wait(0.2)
	Dice1.Anchored = false
end

function DicesAnchoredTrue()
	Dice1.Anchored = true
	Dice2.Anchored = true
end

--Event
ClickDetector.MouseClick:Connect(function()
	ButtonPress()
	DicesAnchoredTrue()
	GeneratePosition()
	GenerateOrientation()
	wait(1)
	ButtonRelease()
	DicesAnchoredFalse()
end)

1 answer

In the GeneratePosition function, you have several lines where the minimum is greater than the maximum. For example:

local X1 = math.random(-17, -19) local Z1 = math.random(-29, -31) local X2 = math.random(-13, -15) local Z2 = math.random(-25, -27)

This should be an easy fix.

In the GenerateOrientation function, you are trying to directly set individual parts of the Vector3. You cannot directly change X or Y in a Vector3.

What you could do is Dice1.Orientation = Vector3.new(math.random(0, 90), math.random(0, 90), math.random(0, 90)).

I also noticed that after you set the Orientation of Dice1, your next lines of code set the Orientation of Dice1 again when I think you mean to change it for Dice2.

I hope this helped solve your problems! If so, please mark this as the solution, if not, please leave a comment telling me what other issues need to be resolved.

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