Interesting Random Placement Bug

I’m trying to make a system in which a part is assigned the position of one of the randomly selected configurations. Each configuration has three numberValues, all with a coordinate with the desired x, y, and x of a Vector3 position value.
image
In valX, valY, and valZ, there are numbers which serve to be the designated positions.
valX, for exmaple:

In the output, I’m getting the bug of “X cannot be assigned”.

here are the script and output:


wait(3)
local ss = game.ServerStorage
local needed = ss["Story I"]["Level 1"]
local clue = needed.Clue


local cluesFolder = workspace["Story I"]["Level 1"].clues
local cluesRandomFolder = workspace["Story I"]["Level 1"].cluePlacement


-- each random represents one of the three findable numbers

local rand1 = math.random(1,9)
local rand2 = math.random(1,9)
local rand3 = math.random(1,9)

-- this math is an expanded form of a(b + c)


local sum1 = rand2 + rand3
-- first sum is the simply the second and third randoms added (or b + c)


local answer = rand1 * sum1
-- this simply multiplies the first random by sum1, following PEMDAS rules.
workspace["Story I"]["Level 1"].answerButton.code.Value = answer
print(rand1)
print(rand2)
print(rand3)
print(sum1)
print(answer)



function getRandomPos(part)
	local fol = cluesRandomFolder:GetChildren()
	local random = math.random(1,#fol)
	local chosen = fol[random]
	part.Position.X = chosen.valX.Value
	part.Position.Y = chosen.valY.Value
	part.Position.Z = chosen.valZ.Value
end


-- pairing the 3 randoms to clues in the workspace

local clone1 =  clue:Clone()
clone1.SurfaceGui.TextLabel.Text = "A = "..rand1
clone1.Parent = workspace
getRandomPos(clone1)


local clone2 =  clue:Clone()
clone2.SurfaceGui.TextLabel.Text = "B = "..rand2
clone2.Parent = workspace
getRandomPos(clone2)

local clone3 =  clue:Clone()
clone3.SurfaceGui.TextLabel.Text = "C = "..rand3
clone3.Parent = workspace
getRandomPos(clone3)

The output:


is there any way to fix this, or does this system need to be reworked?

All help is appreciated.

you would need to create a new vector to change the position

wait(3)
local ss = game.ServerStorage
local needed = ss["Story I"]["Level 1"]
local clue = needed.Clue


local cluesFolder = workspace["Story I"]["Level 1"].clues
local cluesRandomFolder = workspace["Story I"]["Level 1"].cluePlacement


-- each random represents one of the three findable numbers

local rand1 = math.random(1,9)
local rand2 = math.random(1,9)
local rand3 = math.random(1,9)

-- this math is an expanded form of a(b + c)


local sum1 = rand2 + rand3
-- first sum is the simply the second and third randoms added (or b + c)


local answer = rand1 * sum1
-- this simply multiplies the first random by sum1, following PEMDAS rules.
workspace["Story I"]["Level 1"].answerButton.code.Value = answer
print(rand1)
print(rand2)
print(rand3)
print(sum1)
print(answer)



function getRandomPos(part)
	local fol = cluesRandomFolder:GetChildren()
	local random = math.random(1,#fol)
	local chosen = fol[random]
	local partPos = Vector3.new(
		chosen.valX.Value,
		chosen.valY.Value,
		chosen.valZ.Value
	)
	part.Position = partPos
end


-- pairing the 3 randoms to clues in the workspace

local clone1 =  clue:Clone()
clone1.SurfaceGui.TextLabel.Text = "A = "..rand1
clone1.Parent = workspace
getRandomPos(clone1)


local clone2 =  clue:Clone()
clone2.SurfaceGui.TextLabel.Text = "B = "..rand2
clone2.Parent = workspace
getRandomPos(clone2)

local clone3 =  clue:Clone()
clone3.SurfaceGui.TextLabel.Text = "C = "..rand3
clone3.Parent = workspace
getRandomPos(clone3)
1 Like

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