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

Expected 'end' (to close 'do' at line 54), got 'else'?

I am trying to solve a issue with code but can't get any further.

Hopefully someone can jump in and help me.

Error: Expected 'end' (to close 'do' at line 54), got 'else'; did you forget to close 'function' at line 292?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19	
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
-- functions

local function Refresh()
	for i, slot in pairs(slots) do
		for _, connection in pairs(slot.Connections) do
			connection:disconnect()
		end
		
		for _, v in pairs(slot.Button.AttachmentFrame:GetChildren()) do
			if v:IsA("GuiObject") then
				v:Destroy()
			end
		end
	end
end

		
		if slot.Item then
			local item		= slot.Item
			local base		= ITEMS[item.Name]
			local config	= require(item:WaitForChild("Config"))
			
			if config.Type == "Gun" or config.Type == "RocketLauncher" then
				local ammo	= item:WaitForChild("Ammo")
				slot.Button.CountLabel.Visible	= true
				slot.Button.CountLabel.Text		= ammo.Value
				
				table.insert(slot.Connections, ammo.Changed:connect(function()
					slot.Button.CountLabel.Text		= ammo.Value
				end))
			elseif config.Type == "Booster" or config.Type == "Throwable" then
				local stack	= item:WaitForChild("Stack")
				slot.Button.CountLabel.Visible	= true
				slot.Button.CountLabel.Text		= stack.Value
				
				table.insert(slot.Connections, stack.Changed:connect(function()
					slot.Button.CountLabel.Text		= stack.Value
				end))
			else
				slot.Button.CountLabel.Visible	= false
			end
			
			slot.Button.Frame.ViewportFrame:ClearAllChildren()
			
			local preview	= base:Clone()
			preview.Parent	= slot.Button.Frame.ViewportFrame
			
			local function UpdateShadow()
				slot.Button.Frame.ViewportShadow:ClearAllChildren()
				
				for _, v in pairs(slot.Button.Frame.ViewportFrame:GetChildren()) do
					v:Clone().Parent	= slot.Button.Frame.ViewportShadow
				end
			end
			
			local function UpdateCFrame()
				local center, size	= preview:GetBoundingBox()
				local offset		= center:toObjectSpace(preview.PrimaryPart.CFrame)
				
				local dist	= math.max(size.X, size.Y, size.Z)
				
				preview:SetPrimaryPartCFrame(CFrame.new(0, 0, 8 + dist * 4) * CFrame.Angles(0, -math.pi / 2, 0) * CFrame.Angles(math.pi / 4, 0, 0) * offset)
				
				UpdateShadow()
			end
			
			if base:FindFirstChild("Attachments") then
				local attachments	= item:WaitForChild("Attachments")
				local pAttachments	= preview:WaitForChild("Attachments")
				
				local function AddAttachment(attachment)
					local attach	= ITEMS[attachment.Name]:Clone()
					local aConfig	= require(attach:WaitForChild("Config"))
					
					local center	= attach.PrimaryPart.Attach
					local iCenter	= preview.PrimaryPart[aConfig.Attach .. "Attach"]
					
					attach:SetPrimaryPartCFrame(iCenter.WorldCFrame * center.CFrame:Inverse())
					attach.Parent	= pAttachments
					
					if not slot.Button.AttachmentFrame:FindFirstChild(attachment.Name) then
						local preview		= ITEMS[attachment.Name]:Clone()
						do
							local center, size	= preview:GetBoundingBox()
							local offset		= center:toObjectSpace(preview.PrimaryPart.CFrame)
							
							local dist	= math.max(size.X, size.Y, size.Z)
							
							preview:SetPrimaryPartCFrame(CFrame.new(0, 0, 2.5 + dist * 4) * CFrame.Angles(0, -math.pi / 4, 0))
						end
						
						local button	= script.ItemAttachmentButton:Clone()
							button.ViewportFrame.CurrentCamera	= ICON_CAMERA
							button.ViewportShadow.CurrentCamera	= ICON_CAMERA
							button.Name				= attachment.Name
							preview.Parent			= button.ViewportFrame
							preview:Clone().Parent	= button.ViewportShadow
							button.Parent			= slot.Button.AttachmentFrame
							
						button.InputBegan:connect(function(inputObject)
							if inputObject.UserInputType == Enum.UserInputType.MouseButton1 or inputObject.KeyCode == Enum.KeyCode.ButtonA then
								if attachment then
									script.DragSound:Play()
									dragging	= true
									
									if DRAGGER_GUI.Display.Frame:FindFirstChild("ViewportFrame") then
										DRAGGER_GUI.Display.Frame.ViewportFrame:Destroy()
									end
									if DRAGGER_GUI.Display.Frame:FindFirstChild("ViewportShadow") then
										DRAGGER_GUI.Display.Frame.ViewportShadow:Destroy()
									end
									button.ViewportFrame:Clone().Parent		= DRAGGER_GUI.Display.Frame
									button.ViewportShadow:Clone().Parent	= DRAGGER_GUI.Display.Frame
									DRAGGER_GUI.Visible	= true
									button.Visible		= false
									
									local targetIndex	= 1
									
									local dropping	= false
									repeat
										RunService.RenderStepped:wait()
										local mouseLoc	= UserInputService:GetMouseLocation()
										local offset	= mouseLoc - DRAGGER_GUI.AbsolutePosition
										
										targetIndex		= math.clamp(math.ceil((offset.X / DRAGGER_GUI.AbsoluteSize.X) * BACKPACK_SIZE), 1, BACKPACK_SIZE)
										
										DRAGGER_GUI.Display.Position	= UDim2.new(0, offset.X, 0, offset.Y - 36)
										DRAGGER_GUI.Selector.Position	= UDim2.new((targetIndex - 1) * 0.25, 0, 0, 0)
										
										local position, size	= DRAGGER_GUI.DropLabel.AbsolutePosition + Vector2.new(0, 36), DRAGGER_GUI.DropLabel.AbsoluteSize
										
										if mouseLoc.X >= position.X and
											mouseLoc.X <= position.X + size.X and
											mouseLoc.Y >= position.Y and
											mouseLoc.Y <= position.Y + size.Y
										then
											dropping	= true
										else
											dropping	= false
										end
										DRAGGER_GUI.DropLabel.ImageTransparency				= dropping and 0.5 or 0.8
										DRAGGER_GUI.DropLabel.IconLabel.ImageTransparency	= dropping and 0 or 0.5
									until not dragging
									
									if dropping then
										button:Destroy()
										REMOTES.Drop:FireServer(attachment)
									else
										if slots[targetIndex].Item and slots[targetIndex].Item:FindFirstChild("Attachments") then
											REMOTES.SwapAttachment:FireServer(attachment, slots[targetIndex].Item)
										end
									end
									
									DRAGGER_GUI.Visible	= false
									if button then
										button.Visible		= true
									end
								end
							end
						end)
					end
					
						button.TouchBegan:connect(function(inputObject)
							if attachment then
								script.DragSound:Play()
								dragging	= true
								
								if DRAGGER_GUI.Display.Frame:FindFirstChild("ViewportFrame") then
									DRAGGER_GUI.Display.Frame.ViewportFrame:Destroy()
								end
								if DRAGGER_GUI.Display.Frame:FindFirstChild("ViewportShadow") then
									DRAGGER_GUI.Display.Frame.ViewportShadow:Destroy()
								end
								button.ViewportFrame:Clone().Parent		= DRAGGER_GUI.Display.Frame
								button.ViewportShadow:Clone().Parent	= DRAGGER_GUI.Display.Frame
								DRAGGER_GUI.Visible	= true
								button.Visible		= false
								
								local targetIndex	= 1
								
								local dropping	= false
								repeat
									RunService.RenderStepped:wait()
									local mouseLoc	= UserInputService:GetMouseLocation()
									local offset	= mouseLoc - DRAGGER_GUI.AbsolutePosition
									
									targetIndex		= math.clamp(math.ceil((offset.X / DRAGGER_GUI.AbsoluteSize.X) * BACKPACK_SIZE), 1, BACKPACK_SIZE)
									
									DRAGGER_GUI.Display.Position	= UDim2.new(0, offset.X, 0, offset.Y - 36)
									DRAGGER_GUI.Selector.Position	= UDim2.new((targetIndex - 1) * 0.25, 0, 0, 0)
									
									local position, size	= DRAGGER_GUI.DropLabel.AbsolutePosition + Vector2.new(0, 36), DRAGGER_GUI.DropLabel.AbsoluteSize
									
									if mouseLoc.X >= position.X and
										mouseLoc.X <= position.X + size.X and
										mouseLoc.Y >= position.Y and
										mouseLoc.Y <= position.Y + size.Y
									then
										dropping	= true
									else
										dropping	= false
									end
									DRAGGER_GUI.DropLabel.ImageTransparency				= dropping and 0.5 or 0.8
									DRAGGER_GUI.DropLabel.IconLabel.ImageTransparency	= dropping and 0 or 0.5
								until not dragging
								
								if dropping then
									button:Destroy()
									REMOTES.Drop:FireServer(attachment)
								else
									if slots[targetIndex].Item and slots[targetIndex].Item:FindFirstChild("Attachments") then
										REMOTES.SwapAttachment:FireServer(attachment, slots[targetIndex].Item)
									end
								end
								
								DRAGGER_GUI.Visible	= false
								if button then
									button.Visible		= true
								end
							end
						end)
					end
				end
				
				local function RemoveAttachment(attachment)
					if pAttachments:FindFirstChild(attachment.Name) then
						pAttachments[attachment.Name]:Destroy()
					end
					if slot.Button.AttachmentFrame:FindFirstChild(attachment.Name) then
						slot.Button.AttachmentFrame[attachment.Name]:Destroy()
					end
				end
				
				for _, child in pairs(attachments:GetChildren()) do
					AddAttachment(child)
				end
				
				table.insert(slot.Connections, attachments.ChildAdded:connect(function(child)
					spawn(function()
						AddAttachment(child)
						UpdateCFrame()
					end)
				end))
				
				table.insert(slot.Connections, attachments.ChildRemoved:connect(function(child)
					RemoveAttachment(child)
					UpdateCFrame()
				end))
			end
			
			UpdateCFrame()
			
			slot.Button.Frame.ViewportFrame.Visible	= true
		else
			--slot.Button.Frame.IconLabel.Visible		= false
			--slot.Button.Frame.ShadowLabel.Visible	= false
			slot.Button.Frame.ViewportFrame.Visible	= false
			
			slot.Button.CountLabel.Visible	= false
		end
	end
end

2 comments

0

what's line 292 you only have 259 lines

0

I updated the post but removed all the lines I did not need to include as otherwise it would have been impossible to include the entire script.

1 answer

Well, it looks like you are using else outside your if statement which was on Line 68. I just copied your code and fixed it in studio. This is how it might look :

--[[1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19  
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50]]
-- functions

local function Refresh()
	for i, slot in pairs(slots) do
		for _, connection in pairs(slot.Connections) do
			connection:disconnect()
		end

		for _, v in pairs(slot.Button.AttachmentFrame:GetChildren()) do
			if v:IsA("GuiObject") then
				v:Destroy()
			end
		end
	end
end


if slot.Item then
	local item      = slot.Item
	local base      = ITEMS[item.Name]
	local config    = require(item:WaitForChild("Config"))

	if config.Type == "Gun" or config.Type == "RocketLauncher" then
		local ammo  = item:WaitForChild("Ammo")
		slot.Button.CountLabel.Visible  = true
		slot.Button.CountLabel.Text     = ammo.Value

		table.insert(slot.Connections, ammo.Changed:connect(function()
			slot.Button.CountLabel.Text     = ammo.Value
		end))
	elseif config.Type == "Booster" or config.Type == "Throwable" then
		local stack = item:WaitForChild("Stack")
		slot.Button.CountLabel.Visible  = true
		slot.Button.CountLabel.Text     = stack.Value

		table.insert(slot.Connections, stack.Changed:connect(function()
			slot.Button.CountLabel.Text     = stack.Value
		end))
	else
		slot.Button.CountLabel.Visible  = false
	end

	slot.Button.Frame.ViewportFrame:ClearAllChildren()

	local preview   = base:Clone()
	preview.Parent  = slot.Button.Frame.ViewportFrame

	local function UpdateShadow()
		slot.Button.Frame.ViewportShadow:ClearAllChildren()

		for _, v in pairs(slot.Button.Frame.ViewportFrame:GetChildren()) do
			v:Clone().Parent    = slot.Button.Frame.ViewportShadow
		end
	end

	local function UpdateCFrame()
		local center, size  = preview:GetBoundingBox()
		local offset        = center:toObjectSpace(preview.PrimaryPart.CFrame)

		local dist  = math.max(size.X, size.Y, size.Z)

		preview:SetPrimaryPartCFrame(CFrame.new(0, 0, 8 + dist * 4) * CFrame.Angles(0, -math.pi / 2, 0) * CFrame.Angles(math.pi / 4, 0, 0) * offset)

		UpdateShadow()
	end

	if base:FindFirstChild("Attachments") then
		local attachments   = item:WaitForChild("Attachments")
		local pAttachments  = preview:WaitForChild("Attachments")

		local function AddAttachment(attachment)
			local attach    = ITEMS[attachment.Name]:Clone()
			local aConfig   = require(attach:WaitForChild("Config"))

			local center    = attach.PrimaryPart.Attach
			local iCenter   = preview.PrimaryPart[aConfig.Attach .. "Attach"]

			attach:SetPrimaryPartCFrame(iCenter.WorldCFrame * center.CFrame:Inverse())
			attach.Parent   = pAttachments

			if not slot.Button.AttachmentFrame:FindFirstChild(attachment.Name) then
				local preview       = ITEMS[attachment.Name]:Clone()
				do
					local center, size  = preview:GetBoundingBox()
					local offset        = center:toObjectSpace(preview.PrimaryPart.CFrame)

					local dist  = math.max(size.X, size.Y, size.Z)

					preview:SetPrimaryPartCFrame(CFrame.new(0, 0, 2.5 + dist * 4) * CFrame.Angles(0, -math.pi / 4, 0))
				end

				local button    = script.ItemAttachmentButton:Clone()
				button.ViewportFrame.CurrentCamera  = ICON_CAMERA
				button.ViewportShadow.CurrentCamera = ICON_CAMERA
				button.Name             = attachment.Name
				preview.Parent          = button.ViewportFrame
				preview:Clone().Parent  = button.ViewportShadow
				button.Parent           = slot.Button.AttachmentFrame

				button.InputBegan:connect(function(inputObject)
					if inputObject.UserInputType == Enum.UserInputType.MouseButton1 or inputObject.KeyCode == Enum.KeyCode.ButtonA then
						if attachment then
							script.DragSound:Play()
							dragging    = true

							if DRAGGER_GUI.Display.Frame:FindFirstChild("ViewportFrame") then
								DRAGGER_GUI.Display.Frame.ViewportFrame:Destroy()
							end
							if DRAGGER_GUI.Display.Frame:FindFirstChild("ViewportShadow") then
								DRAGGER_GUI.Display.Frame.ViewportShadow:Destroy()
							end
							button.ViewportFrame:Clone().Parent     = DRAGGER_GUI.Display.Frame
							button.ViewportShadow:Clone().Parent    = DRAGGER_GUI.Display.Frame
							DRAGGER_GUI.Visible = true
							button.Visible      = false

							local targetIndex   = 1

							local dropping  = false
							repeat
								RunService.RenderStepped:wait()
								local mouseLoc  = UserInputService:GetMouseLocation()
								local offset    = mouseLoc - DRAGGER_GUI.AbsolutePosition

								targetIndex     = math.clamp(math.ceil((offset.X / DRAGGER_GUI.AbsoluteSize.X) * BACKPACK_SIZE), 1, BACKPACK_SIZE)

								DRAGGER_GUI.Display.Position    = UDim2.new(0, offset.X, 0, offset.Y - 36)
								DRAGGER_GUI.Selector.Position   = UDim2.new((targetIndex - 1) * 0.25, 0, 0, 0)

								local position, size    = DRAGGER_GUI.DropLabel.AbsolutePosition + Vector2.new(0, 36), DRAGGER_GUI.DropLabel.AbsoluteSize

								if mouseLoc.X >= position.X and
									mouseLoc.X <= position.X + size.X and
									mouseLoc.Y >= position.Y and
									mouseLoc.Y <= position.Y + size.Y
								then
									dropping    = true
								else
									dropping    = false
								end
								DRAGGER_GUI.DropLabel.ImageTransparency             = dropping and 0.5 or 0.8
								DRAGGER_GUI.DropLabel.IconLabel.ImageTransparency   = dropping and 0 or 0.5
							until not dragging

							if dropping then
								button:Destroy()
								REMOTES.Drop:FireServer(attachment)
							else
								if slots[targetIndex].Item and slots[targetIndex].Item:FindFirstChild("Attachments") then
									REMOTES.SwapAttachment:FireServer(attachment, slots[targetIndex].Item)
								end
							end

							DRAGGER_GUI.Visible = false
							if button then
								button.Visible      = true
							end
						end
					end
				end)
			end

			button.TouchBegan:connect(function(inputObject)
				if attachment then
					script.DragSound:Play()
					dragging    = true

					if DRAGGER_GUI.Display.Frame:FindFirstChild("ViewportFrame") then
						DRAGGER_GUI.Display.Frame.ViewportFrame:Destroy()
					end
					if DRAGGER_GUI.Display.Frame:FindFirstChild("ViewportShadow") then
						DRAGGER_GUI.Display.Frame.ViewportShadow:Destroy()
					end
					button.ViewportFrame:Clone().Parent     = DRAGGER_GUI.Display.Frame
					button.ViewportShadow:Clone().Parent    = DRAGGER_GUI.Display.Frame
					DRAGGER_GUI.Visible = true
					button.Visible      = false

					local targetIndex   = 1

					local dropping  = false
					repeat
						RunService.RenderStepped:wait()
						local mouseLoc  = UserInputService:GetMouseLocation()
						local offset    = mouseLoc - DRAGGER_GUI.AbsolutePosition

						targetIndex     = math.clamp(math.ceil((offset.X / DRAGGER_GUI.AbsoluteSize.X) * BACKPACK_SIZE), 1, BACKPACK_SIZE)

						DRAGGER_GUI.Display.Position    = UDim2.new(0, offset.X, 0, offset.Y - 36)
						DRAGGER_GUI.Selector.Position   = UDim2.new((targetIndex - 1) * 0.25, 0, 0, 0)

						local position, size    = DRAGGER_GUI.DropLabel.AbsolutePosition + Vector2.new(0, 36), DRAGGER_GUI.DropLabel.AbsoluteSize

						if mouseLoc.X >= position.X and
							mouseLoc.X <= position.X + size.X and
							mouseLoc.Y >= position.Y and
							mouseLoc.Y <= position.Y + size.Y
						then
							dropping    = true
						else
							dropping    = false
						end
						DRAGGER_GUI.DropLabel.ImageTransparency             = dropping and 0.5 or 0.8
						DRAGGER_GUI.DropLabel.IconLabel.ImageTransparency   = dropping and 0 or 0.5
					until not dragging

					if dropping then
						button:Destroy()
						REMOTES.Drop:FireServer(attachment)
					else
						if slots[targetIndex].Item and slots[targetIndex].Item:FindFirstChild("Attachments") then
							REMOTES.SwapAttachment:FireServer(attachment, slots[targetIndex].Item)
						end
					end

					DRAGGER_GUI.Visible = false
					if button then
						button.Visible      = true
					end
				end
			end)
		end
	end

	local function RemoveAttachment(attachment)
		if pAttachments:FindFirstChild(attachment.Name) then
			pAttachments[attachment.Name]:Destroy()
		end
		if slot.Button.AttachmentFrame:FindFirstChild(attachment.Name) then
			slot.Button.AttachmentFrame[attachment.Name]:Destroy()
		end
	end

	for _, child in pairs(attachments:GetChildren()) do
		AddAttachment(child)
	end

	table.insert(slot.Connections, attachments.ChildAdded:connect(function(child)
		spawn(function()
			AddAttachment(child)
			UpdateCFrame()
		end)
	end))

	table.insert(slot.Connections, attachments.ChildRemoved:connect(function(child)
		RemoveAttachment(child)
		UpdateCFrame()
	end))
	
	UpdateCFrame()
	
	slot.Button.Frame.ViewportFrame.Visible = true
else
	--slot.Button.Frame.IconLabel.Visible       = false
	--slot.Button.Frame.ShadowLabel.Visible = false
	slot.Button.Frame.ViewportFrame.Visible = false

	slot.Button.CountLabel.Visible  = false
end

Lemme know if it helps!

1 comment

0

Sadly it did not, every fix pops up a new error. The game dates back to 2016 and hasn''t been updated since 2018. Probs deprecated code. Thanks for the help though

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