I wanted to randomly change the position of 2 parts called “StartPos and EndPos” by using:
local StartPos,EndPos = script.Parent,workspace.EndPos
while true do
StartPos.Position.X = EndPos.Position.X == math.random(-300,200)
StartPos.Position.Y = EndPos.Position.Y == math.random(-200,286)
wait(5)
end
but I was met with “X cannot be assigned to”.
I would appreciate it if someone can tell me what did I do wrong, thank you!
local StartPos,EndPos = script.Parent,workspace.EndPos
while true do
StartPos.Position = Vector3.new(math.random(-300,200),math.random(-300,200),0)
task.wait(5)
end
I dont think you could assign the X,Y and Z values separately like this.
(They are ‘readable’ only values.)
EDIT: Actually no, forget about my post, because I never used the EndPos variable and I think that’s probably not what you meant, so it’s good if you explained what you wanted to make
EndPos.Position.X == math.random(-300,200) returns a bool (true or false), not a number, so your line
Additionally Position is a changeable value, but Position.X or Position.Y is a readable value. A solution is to do this:
local StartPos,EndPos = script.Parent,workspace.EndPos
while true do
StartPos.Position = Vector3.new(math.random(-300,200), math.random(-200,286), 0)
wait(5)
end
You can’t assign a boolean to it, when you declare “EndPos.Position.X == math.random(-300,200)” you really are asigned a boolean value. Apparently you need declare a position and then you match the positions. I don’t understand what you did. Can you explain me?