Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

2 random blocks not working?

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

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)

8 comments

0

Just supplying code and not an explanation doesn't help anyone learn, please supply an explanation as to why your answer fixed anything.

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...'.

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

0

this website have some of the most non-frugal thinking minds

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

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.

0

great more stupid rules no wonder you dont get alot of visitors

0

You have already broken Rules 1, 4, and 7 of the Guidelines, please do not use that type of Language.

This discussion is preserved as it was. New answers, comments, and votes are closed.