My part only chooses one position instead of randomly choosing one every 1 second.
Video if you are confused:
So basically, my initial thought going into this was that the part was going to change position every time the loop ran, but instead, the part only chooses one position and sticks with it
Code (You really only need to worry about the positioners in the loop.
local x = math.random(-110,-4)
local y = math.random(19, 31)
local teapot = game.ServerStorage.Teapot
local flingPart = script.Parent
local waitTime = (math.random(5,7)*.1)
print(waitTime)
while true do
wait(waitTime)
local newTeapot = teapot:Clone()
newTeapot.Parent = game.Workspace.Teapots
newTeapot.Position = Vector3.new(x,y,0)
local a = math.random(1, 255)
local b = math.random(1, 255)
local c = math.random(1, 255)
newTeapot.Color = Color3.fromRGB(a, b, c)
wait()
end
Please let me know if you have a solution. Thank you.
When you are assigning the x and y variables at the start of your code snippet, math.random() acts only one time. If you want it to repeatedly give you new values, you should move those variable declarations into the loop. (Assuming you don’t need to use the x/y variables outside of the loop. You’d take a slightly different approach if you need to use them later in the code.)
local teapot = game.ServerStorage.Teapot
local flingPart = script.Parent
local waitTime = (math.random(5,7)*.1)
print(waitTime)
while true do
wait(waitTime)
local x = math.random(-110,-4)
local y = math.random(19, 31)
local newTeapot = teapot:Clone()
newTeapot.Parent = game.Workspace.Teapots
newTeapot.Position = Vector3.new(x,y,0)
local a = math.random(1, 255)
local b = math.random(1, 255)
local c = math.random(1, 255)
newTeapot.Color = Color3.fromRGB(a, b, c)
wait()
end