The purpose of this script is to raise and descend 2 random block in the jumparts model in a continuous loop until there is no more blocks in jumparts to raise, but what it does is raise the same blocks over and over again . I do not get any output errors and yes the debounce code works perfect. The blocks are random at the start but it just keeps raising and descending those 2 random block chosen at the start. Thanks for taking your time to read this post. I was to lazy to make a function for random numbers haha.
jumparts={} for i,v in pairs(game.Workspace.jumparts:GetChildren())do table.insert(jumparts,i,v) end function ranNum() 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] if enabled==true then enabled=false script.Parent.BrickColor=BrickColor.new("Really red") for i,v in pairs(jumparts)do while true do for i=4,13,0.3 do blockChosen.CFrame=CFrame.new(blockChosen.Position.x,blockChosen.Position.y+1.1,blockChosen.Position.z) blockChosen2.CFrame=CFrame.new(blockChosen2.Position.x,blockChosen2.Position.y+1.1,blockChosen2.Position.z) wait(0.1) end wait(1) for i=13,4,-0.3 do blockChosen.CFrame=CFrame.new(blockChosen.Position.x,blockChosen.Position.y-1.1,blockChosen.Position.z) blockChosen2.CFrame=CFrame.new(blockChosen2.Position.x,blockChosen2.Position.y-1.1,blockChosen2.Position.z) wait(0.1) end table.remove(jumparts,ranNum1) table.remove(jumparts,ranNum2) local ranNum1=math.random(1,#jumparts) local ranNum2=ranNum1 while ranNum1==ranNum2 do ranNum2=math.random(1,#jumparts) wait() end end end end script.Parent.BrickColor=BrickColor.new("Lime green") enabled=true end enabled=true function onClicked() ranNum() end script.Parent.ClickDetector.MouseClick:connect(onClicked)
I fixed it i need to add blockChosen=jumparts[ranNum1] blockChosen2=jumparts[ranNum2]
after the while loop.
jumparts={} for i,v in pairs(game.Workspace.jumparts:GetChildren())do table.insert(jumparts,i,v) end function ranNum() 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] if enabled==true then enabled=false script.Parent.BrickColor=BrickColor.new("Really red") for i,v in pairs(jumparts)do while true do for i=4,13,0.3 do blockChosen.CFrame=CFrame.new(blockChosen.Position.x,blockChosen.Position.y+1.1,blockChosen.Position.z) blockChosen2.CFrame=CFrame.new(blockChosen2.Position.x,blockChosen2.Position.y+1.1,blockChosen2.Position.z) wait(0.1) end wait(1) for i=13,4,-0.3 do blockChosen.CFrame=CFrame.new(blockChosen.Position.x,blockChosen.Position.y-1.1,blockChosen.Position.z) blockChosen2.CFrame=CFrame.new(blockChosen2.Position.x,blockChosen2.Position.y-1.1,blockChosen2.Position.z) wait(0.1) end table.remove(jumparts,ranNum1) table.remove(jumparts,ranNum2) local ranNum1=math.random(1,#jumparts) local ranNum2=ranNum1 while ranNum1==ranNum2 do ranNum2=math.random(1,#jumparts) wait() end blockChosen=jumparts[ranNum1] blockChosen2=jumparts[ranNum2] end end end script.Parent.BrickColor=BrickColor.new("Lime green") enabled=true end enabled=true function onClicked() ranNum() end script.Parent.ClickDetector.MouseClick:connect(onClicked)