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

How to break a loop inside a function, that is inside a loop?

How to break a loop in a function?

--The client cannot access ServerStorage, use ReplicatedStorage
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local pump = game.ReplicatedStorage.Derrick 
local pump1Good = game.ReplicatedStorage.DerrickColorGood
local isButtonDown = false
local Clonedpump
local selectionBox = Instance.new("SelectionBox")
local enabled = false
local pump1Bad = game.ReplicatedStorage.DerrickColorBad
local function roundToGrid(v, size)
    return Vector3.new(
        math.floor(v.x*size + 0.5)/size,
        math.floor(v.y*size + 0.5)/size,
        math.floor(v.z*size + 0.5)/size
    )
end
script.Parent.MouseButton1Down:connect(function()
   if not enabled then
      enabled = true
	script.Parent.Parent.Parent.BuildFrame.Visible = false
repeat
	--Good
	
--Input Break Function

local uis = game:GetService('UserInputService')
uis.InputBegan:connect(function(input,process)
    if not process then
        if input.KeyCode == Enum.KeyCode.E then
            break
        end
    end
end)



	if mouse.Target == workspace.Oil then
	if mouse.Target.Check.Value == 1 then
	  pump1Bad.Parent = game.ReplicatedStorage
	  pump1Good.Parent = game.Workspace
      mouse.TargetFilter = pump1Good
      selectionBox.Adornee = pump1Good
      selectionBox.Color3 = Color3.new(0,255,0)
      selectionBox.Parent = pump1Good
      pump1Good.Position = roundToGrid(mouse.Hit.p, 1)
	else
	  pump1Bad.Parent = game.Workspace
	  pump1Good.Parent = game.ReplicatedStorage
      mouse.TargetFilter = pump1Bad
      selectionBox.Adornee = pump1Bad
      selectionBox.Color3 = Color3.new(255,0,0)
      selectionBox.Parent = pump1Bad
      pump1Bad.Position = roundToGrid(mouse.Hit.p, 1)
		end
	end
	--Bad
	if mouse.Target == workspace.Terrain.Land then
	  pump1Bad.Parent = game.Workspace
	  pump1Good.Parent = game.ReplicatedStorage
      mouse.TargetFilter = pump1Bad
      selectionBox.Adornee = pump1Bad
      selectionBox.Color3 = Color3.new(255,0,0)
      selectionBox.Parent = pump1Bad
      pump1Bad.Position = roundToGrid(mouse.Hit.p, 1)
	end
	if mouse.Target == workspace.Derrick then
	  pump1Bad.Parent = game.Workspace
	  pump1Good.Parent = game.ReplicatedStorage
      mouse.TargetFilter = pump1Bad
      selectionBox.Adornee = pump1Bad
      selectionBox.Color3 = Color3.new(255,0,0)
      selectionBox.Parent = pump1Bad
      pump1Bad.Position = roundToGrid(mouse.Hit.p, 1)
	end
      wait()
--Untill HERERERE
until not enabled

	else
   enabled = false
   pump1Bad.Parent = game.ReplicatedStorage
   pump1Good.Parent = game.ReplicatedStorage
end
end)

mouse.Button1Down:connect(function()
   if enabled then
		if mouse.Target == workspace.Oil then
			if mouse.Target.Check.Value == 0 then
				return
			else
				mouse.Target.Check.Value = 0
				local randomDirection = math.random(4)
		        Clonedpump = pump:Clone()
		        mouse.TargetFilter = pump
		        mouse.TargetFilter = pump1Good
				if randomDirection == 1 then
					Clonedpump.Orientation = Vector3.new(0,90,-90)
				end
				if randomDirection == 2 then
					Clonedpump.Orientation = Vector3.new(0,180,-90)
				end
				if randomDirection == 3 then
					Clonedpump.Orientation = Vector3.new(0,-90,-90)
				end
				if randomDirection == 4 then
					Clonedpump.Orientation = Vector3.new(0,0,-90)
				end
		        Clonedpump.Position = roundToGrid(mouse.Hit.p, 1) + Vector3.new(0,2.8,0)
		        Clonedpump.Parent = workspace 
				pump1Bad.Parent = game.ReplicatedStorage
		   		pump1Good.Parent = game.ReplicatedStorage
				print("Orientation Direction "..randomDirection)
				enabled = false
	  		end
		end
  	end
end)

or

while true do
	script.Parent.Touched:connect(function()
		break
	end
end

1 comment

0

Try putting lines 27-34 before line 18, and replace the break with enabled = false within it.

1 answer

✓ Accepted answer
~~~~~~~~~~~~~~~~~

script.Parent.MouseButton1Down:connect(function() if not enabled then enabled = true script.Parent.Parent.Parent.BuildFrame.Visible = false spawn(function() repeat --Good

   --Input Break Function

  local uis = game:GetService('UserInputService')
  uis.InputBegan:connect(function(input,process)
      if not process then
         if input.KeyCode == Enum.KeyCode.E then
            break
         end
      end
  end)

--put stuff here

until not enabled end) else enabled = false pump1Bad.Parent = game.ReplicatedStorage pump1Good.Parent = game.ReplicatedStorage end end)



Something like that.
And remove line 115.

2 comments

1

Uhm your code block messed up.

0

Yeah, not sure why. We ended up fixing the code, and it had nothing to do with what I wrote anyway.

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