Why is the elseif in this script breaking it?

I’m redoing a plot system I created a long time ago for my current project. I’m trying to detect if when the MouseEnter event is fired. I’m not sure why but my script just doesn’t do anything when my mouse enters the TextButton with the elseif statement in the loop. Does anyone know why?

local player = game.Players.LocalPlayer
local plotHolder = workspace.Plots
local gui = player:WaitForChild("PlayerGui"):WaitForChild("gui")
local plots = gui.plotSelect.holder
local frame = gui.plotSelect
local clientServer = game.ReplicatedStorage.clientServer

for holder,plot in pairs(plots:GetChildren()) do
	if plot.ClassName == "TextButton" then
		plot.MouseEnter:Connect(function()
			local selPlot = tostring(plot.Name)			
			local match = plotHolder:FindFirstChild(selPlot)
			local outline = match:WaitForChild("select")
			
			if match:WaitForChild("Owner").Value == "" then
				outline.Visible = true
				
			elseif match:WaitForChild("Owner").Value ~= "" then
				outline.Color3 = Color3.fromRGB(222, 54, 54)
				outline.Visible = true

		plot.MouseLeave:Connect(function()
			local selPlot = tostring(plot.Name)			
			local match = plotHolder:FindFirstChild(selPlot)			
			local outline = match:WaitForChild("select")
			
			if match and outline then
				outline.Visible = false
					
		plot.MouseButton1Click:Connect(function()
			frame:TweenPosition(UDim2.new(0.5,0,1.5,0),"In","Bounce",1.25)
			clientServer:FireServer("plotSelect", tostring(match))
			
		end)
		end
		end)
		end
	end
	end)
	end
end
1 Like

You got the end statements wrong. Beggining from the top you must put “end” two times above the MouseLeave Event like that.

if match:WaitForChild("Owner").Value == "" then
	outline.Visible = true
				
	elseif match:WaitForChild("Owner").Value ~= "" then
		outline.Color3 = Color3.fromRGB(222, 54, 54)
		outline.Visible = true
       end
end

And here the same issue because of the wrong placed end statements. The MouseButton1Click will only fire when the mouse button leaves to the same time.

plot.MouseLeave:Connect(function()
	local selPlot = tostring(plot.Name)			
	local match = plotHolder:FindFirstChild(selPlot)			
	local outline = match:WaitForChild("select")
			
	if match and outline then
		outline.Visible = false
        end
end)
					
	plot.MouseButton1Click:Connect(function()
		frame:TweenPosition(UDim2.new(0.5,0,1.5,0),"In","Bounce",1.25)
		clientServer:FireServer("plotSelect", tostring(match))
			
	end)

I hope you understand where the problem is with wrong placed end statements. They can break your whole code.

1 Like

I appreciate the help! It means a lot! I kind of understand about the end placing, probably be something for me to look into a little more! But, again thank you for your help!