what this script does is it ascends and descends the 2 random rocks(just parts) in the table jumparts. The script works but the button(also a part) color does not change to green after it is done which is very bizzare any ideas? If you read the script it explains itself i made the table jumparts by using a generic loop and loop through a model in workspace then adding it to the table. No errors either.
enabled=true
jumparts={}
for i,v in pairs(game.Workspace.jumparts:GetChildren())do
table.insert(jumparts,i,v)
end
function ranNum()
if enabled==true then
enabled=false
script.Parent.BrickColor=BrickColor.new("Really red")
local ranNum1=math.random(1,#jumparts)
local ranNum2=ranNum1
while ranNum1==ranNum2 do
ranNum2=math.random(1,#jumparts)
wait()
end
local blockChosen=jumparts[ranNum1]
local blockChosen2=jumparts[ranNum2]
local chosenOne={blockChosen,blockChosen2}
while jumparts~={} do
for i=4,13,0.3 do
blockChosen.CFrame=CFrame.new(chosenOne[1].Position.x,chosenOne[1].Position.y+1.1,chosenOne[1].Position.z)
blockChosen2.CFrame=CFrame.new(chosenOne[2].Position.x,chosenOne[2].Position.y+1.1,chosenOne[2].Position.z)
wait(0.1)
end
wait(1)
for i=13,4,-0.3 do
blockChosen.CFrame=CFrame.new(chosenOne[1].Position.x,chosenOne[1].Position.y-1.1,chosenOne[1].Position.z)
blockChosen2.CFrame=CFrame.new(chosenOne[2].Position.x,chosenOne[2].Position.y-1.1,chosenOne[2].Position.z)
wait(0.1)
end
table.remove(jumparts,ranNum1)
table.remove(jumparts,ranNum2)
if jumparts ~={} then
ranNum1=math.random(1,#jumparts)
ranNum2=ranNum1
while ranNum1==ranNum2 do
ranNum2=math.random(1,#jumparts)
wait()
end
blockChosen=jumparts[ranNum1]
blockChosen2=jumparts[ranNum2]
chosenOne={blockChosen,blockChosen2}
end
end
enabled=true
script.Parent.BrickColor=BrickColor.new("Lime green")
end
end
function onClicked()
ranNum()
end
script.Parent.ClickDetector.MouseClick:connect(onClicked)

3 comments
thank you (scratch head)
you have to put chosenA and chosenB in the while loop because it only gets the random values once so it does not continuously do the same to blocks but other then that awesome answer.
Oops, that was a mistake when I was arranging my answer