Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

2 random blocks not working?

Asked by 9 years ago

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)

1 answer

Log in to vote
-1
Answered by 9 years ago
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)

0
Just supplying code and not an explanation doesn't help anyone learn, please supply an explanation as to why your answer fixed anything. Goulstem 8144 — 9y
0
Do not use the 'Answer' feature to reply to someone, it signifies that someone has Answered your Question! Use the Comments feature of the site, which can be found BELOW your Question or Answer, it's a Rectangular Box which says 'Post a comments...'. TheeDeathCaster 2368 — 9y
0
You bastards make up the most stupid rules on this site i cannot have a post without you admins complaining all the time sometimes that "BOX" you are talking about does not show up dont ask me why and i did supply an explanation so stop complaining threatboy101 2 — 9y
0
this website have some of the most non-frugal thinking minds threatboy101 2 — 9y
View all comments (4 more)
0
We are ALLOWED to Moderate users! Also, the rules are not 'stupid' as you claim, and by your Comment replies, it is breaking some of the rules. Guidelines: https://scriptinghelpers.org/help/community-guidelines How to post good Answers and Questions: https://scriptinghelpers.org/help/how-post-good-questions-answers TheeDeathCaster 2368 — 9y
0
Also, when did our Comments ever say anything about the Sites Rules? Because, you brought up that the Rules were 'stupid', when we were telling you Warnings, and heads ups. TheeDeathCaster 2368 — 9y
0
great more stupid rules no wonder you dont get alot of visitors threatboy101 2 — 9y
0
You have already broken Rules 1, 4, and 7 of the Guidelines, please do not use that type of Language. TheeDeathCaster 2368 — 9y
Ad

Answer this question