Code autocompletes something seemingly incorrect

Alright so I’m trying to make some basic code for buttons but I’ve reached a point where seemingly there’s an error where there isn’t supposed to be. I decided to post it here to see if anyone could catch something that I couldn’t.

I’m not sure if its because of the amount of checks I added in it

local buttonFolder = script.Parent:WaitForChild("Buttons")

local function InitButton(button) do
		
	end -- the problem is here. the bottom half of my code creates red underlines when removing this

end



for _,v in pairs(buttonFolder:GetChildren()) do
	if v:FindFirstChild("Head") then
		v.Head.Touched:Connect(function(hit)
			local player = game.Players:GetPlayerFromCharacter(hit.Parent)
			if player then
				if script.Parent.Owner.Value == player then
					if hit.Parent:FindFirstChild("Humanoid") then
						if hit.Parent.Humanoid.Health > 0 then
							local moneyVal = player:FindFirstChild("leaderstats").Money
							if moneyVal then
								if player.leaderstats.Money >= v.Price.Value then
										player.leaderstats.Money = player.leaderstats.Money - v.Price.Value
								end
							end
						end
					end
				end
			end
		end)
	end
end

help would be greatly appreciated

when making the function, the script autocompleted 2 end keywords instead of one

First I’d clean this up, you can use the continue keyword.
So instead of the first check it’d look more like:

if not v:FindFirstChild("Head") then
    continue
end

alright will do, but what about the function at the top of the code?

it doesn’t make much sense to me why its making two ends instead of one

like when I remove the entire loop at the bottom, it still makes an error

oh didn’t notice that, i’d still clean up the loop though

it’s because you used the “do” keyword

1 Like

ah yes i see thank you for this

the loop is pretty messy rn ik lol

1 Like