How to correctly end functions?

Does 1 if count as 1 end? I’m really stuck at a problem that I think also include indentation; I am lost.

shop:WaitForChild("CommonCrate").Activated:Connect(function()
	shop:WaitForChild("Percent").Text = "80% Common, 20% Rare"
	shop:WaitForChild("Price").PriceCost.Text = commonprice
	shop:WaitForChild("Rarity").RarityClass.Text = "Common"
	shop:WaitForChild("Weapon1").Image = "http://www.roblox.com/asset/?id=15815122246"
	shop:WaitForChild("Weapon2").Image = "http://www.roblox.com/asset/?id=15815122246"
	shop:WaitForChild("Weapon3").Image = "http://www.roblox.com/asset/?id=15815122246"
	shop:WaitForChild("Weapon4").Image = "http://www.roblox.com/asset/?id=15815122246"
	shop:WaitForChild("Weapon5").Image = "http://www.roblox.com/asset/?id=15815122246"
	shop:WaitForChild("BuyCrate").Activated:Connect(function()
		if buying == true then
			buying = false
			local coins = game.Players.LocalPlayer:WaitForChild("leaderstats"):WaitForChild("Coins")
			coins.Value = coins.Value - commonprice
			wpnpicker.Visible = true
			shop.Visible = false
			local wpnnumber = math.random(1, 5)
			if wpnnumber == 1 and taking == true then
				taking = false
				wait(1.5)
				wpn.Image = "http://www.roblox.com/asset/?id=15815122246"
				wait(0.2)
				wpn.Image = "http://www.roblox.com/asset/?id=15815360753"
				wait(0.2)
				wpn.Image = "http://www.roblox.com/asset/?id=15815521319"
				wait(0.2)
				wpn.Image = "http://www.roblox.com/asset/?id=15815517787"
				wait(0.2) 
				wpn.Image = "http://www.roblox.com/asset/?id=15815483256"
				wait(0.2)
				wpn.Image = "http://www.roblox.com/asset/?id=15815122246"
				wait(0.2)
				wpn.Image = "http://www.roblox.com/asset/?id=15815360753"
				wait(0.2)
				wpn.Image = "http://www.roblox.com/asset/?id=15815521319"
				wait(0.2)
				wpn.Image = "http://www.roblox.com/asset/?id=15815517787"
				wait(0.2) 
				wpn.Image = "http://www.roblox.com/asset/?id=15815483256"
				wait(0.2)
				wpn.Image = "http://www.roblox.com/asset/?id=15815122246"
				wait(0.2)
				wpn.Image = "http://www.roblox.com/asset/?id=15815360753"
				wait(0.2)
				wpn.Image = "http://www.roblox.com/asset/?id=15815521319"
				wait(0.2)
				wpn.Image = "http://www.roblox.com/asset/?id=15815517787"
				wait(0.2) 
				wpn.Image = "http://www.roblox.com/asset/?id=15815483256"
				wait(0.2)
				wpn.Image = "http://www.roblox.com/asset/?id=15815122246"
				wait(0.3)
				wpn.Image = "http://www.roblox.com/asset/?id=15815360753"
				wait(0.3)
				wpn.Image = "http://www.roblox.com/asset/?id=15815521319"
				wait(0.3)
				wpn.Image = "http://www.roblox.com/asset/?id=15815517787"
				wait(0.4) 
				wpn.Image = "http://www.roblox.com/asset/?id=15815483256"
				wait(0.4)
				wpn.Image = "http://www.roblox.com/asset/?id=15815122246"
				wait(0.4)
				wpn.Image = "http://www.roblox.com/asset/?id=15815360753"
				wait(0.4)
				wpn.Image = "http://www.roblox.com/asset/?id=15815521319"
				wait(0.5)
				wpn.Image = "http://www.roblox.com/asset/?id=15815517787"
				wait(0.5) 
				wpn.Image = "http://www.roblox.com/asset/?id=15815483256"
				wpnname.Text = cmntools:FindFirstChild("1Dagger5").Name
				wait(3)
				local dagger1 = cmntools:FindFirstChild("1Dagger5"):Clone()
				dagger1.Parent = game.Players.LocalPlayer.Backpack
				wpnpicker.Visible = false
				wait(2)
				taking = true
				if wpn1.Image == "" and imgplacing == true then
					imgplacing = false
					wpn1.Image = "http://www.roblox.com/asset/?id=15815483256"
					wait(2)
					imgplacing = true
				elseif wpn1.Image ~= "" then

					if wpn2.Image == "" and imgplacing == true then
						imgplacing = false
						wpn2.Image = "http://www.roblox.com/asset/?id=15815483256"
						wait(2) 
						imgplacing = true
				
					
			

		
						
					

											

							
									
		
	
end)

I accidentally deleted end code blocks and I can’t undo, I also changed several parts of the script(elseifs).

Every if will require its own end unless it is an elseif

shop:WaitForChild("CommonCrate").Activated:Connect(function()
	shop:WaitForChild("Percent").Text = "80% Common, 20% Rare"
	shop:WaitForChild("Price").PriceCost.Text = commonprice
	shop:WaitForChild("Rarity").RarityClass.Text = "Common"
	shop:WaitForChild("Weapon1").Image = "http://www.roblox.com/asset/?id=15815122246"
	shop:WaitForChild("Weapon2").Image = "http://www.roblox.com/asset/?id=15815122246"
	shop:WaitForChild("Weapon3").Image = "http://www.roblox.com/asset/?id=15815122246"
	shop:WaitForChild("Weapon4").Image = "http://www.roblox.com/asset/?id=15815122246"
	shop:WaitForChild("Weapon5").Image = "http://www.roblox.com/asset/?id=15815122246"
	
	shop:WaitForChild("BuyCrate").Activated:Connect(function()
		if buying == true then
			buying = false
			
			local coins = game.Players.LocalPlayer:WaitForChild("leaderstats"):WaitForChild("Coins")
			
			coins.Value = coins.Value - commonprice
			wpnpicker.Visible = true
			shop.Visible = false
			
			local wpnnumber = math.random(1, 5)
			
			if wpnnumber == 1 and taking == true then
				taking = false
				wait(1.5)
				wpn.Image = "http://www.roblox.com/asset/?id=15815122246"
				wait(0.2)
				wpn.Image = "http://www.roblox.com/asset/?id=15815360753"
				wait(0.2)
				wpn.Image = "http://www.roblox.com/asset/?id=15815521319"
				wait(0.2)
				wpn.Image = "http://www.roblox.com/asset/?id=15815517787"
				wait(0.2) 
				wpn.Image = "http://www.roblox.com/asset/?id=15815483256"
				wait(0.2)
				wpn.Image = "http://www.roblox.com/asset/?id=15815122246"
				wait(0.2)
				wpn.Image = "http://www.roblox.com/asset/?id=15815360753"
				wait(0.2)
				wpn.Image = "http://www.roblox.com/asset/?id=15815521319"
				wait(0.2)
				wpn.Image = "http://www.roblox.com/asset/?id=15815517787"
				wait(0.2) 
				wpn.Image = "http://www.roblox.com/asset/?id=15815483256"
				wait(0.2)
				wpn.Image = "http://www.roblox.com/asset/?id=15815122246"
				wait(0.2)
				wpn.Image = "http://www.roblox.com/asset/?id=15815360753"
				wait(0.2)
				wpn.Image = "http://www.roblox.com/asset/?id=15815521319"
				wait(0.2)
				wpn.Image = "http://www.roblox.com/asset/?id=15815517787"
				wait(0.2) 
				wpn.Image = "http://www.roblox.com/asset/?id=15815483256"
				wait(0.2)
				wpn.Image = "http://www.roblox.com/asset/?id=15815122246"
				wait(0.3)
				wpn.Image = "http://www.roblox.com/asset/?id=15815360753"
				wait(0.3)
				wpn.Image = "http://www.roblox.com/asset/?id=15815521319"
				wait(0.3)
				wpn.Image = "http://www.roblox.com/asset/?id=15815517787"
				wait(0.4) 
				wpn.Image = "http://www.roblox.com/asset/?id=15815483256"
				wait(0.4)
				wpn.Image = "http://www.roblox.com/asset/?id=15815122246"
				wait(0.4)
				wpn.Image = "http://www.roblox.com/asset/?id=15815360753"
				wait(0.4)
				wpn.Image = "http://www.roblox.com/asset/?id=15815521319"
				wait(0.5)
				wpn.Image = "http://www.roblox.com/asset/?id=15815517787"
				wait(0.5) 
				wpn.Image = "http://www.roblox.com/asset/?id=15815483256"
				wpnname.Text = cmntools:FindFirstChild("1Dagger5").Name
				
				wait(3)
				
				local dagger1 = cmntools:FindFirstChild("1Dagger5"):Clone()
				dagger1.Parent = game.Players.LocalPlayer.Backpack
				wpnpicker.Visible = false
				
				wait(2)
				
				taking = true
				
				if wpn1.Image == "" and imgplacing == true then
					imgplacing = false
					wpn1.Image = "http://www.roblox.com/asset/?id=15815483256"
					wait(2)
					imgplacing = true
				elseif wpn1.Image ~= "" then

					if wpn2.Image == "" and imgplacing == true then
						imgplacing = false
						wpn2.Image = "http://www.roblox.com/asset/?id=15815483256"
						wait(2) 
						imgplacing = true
					end
				end
			end
		end
	end)
end)

Like this

Also fixed your indentation and added empty lines to make it appear cleaner

1 Like

Lifesaver, my head was about to implode, thinking it would have to read 1.4k lines of code to find one mistake.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.