Expected 'end' (to close 'do' at line 5), got <eof>; did you forget to close 'then' at line 9?

Hello,

So I’m a newbie practicing making a script from scratch and I’m getting an error which I really can’t see what’s wrong. I’ve been watching TheDevKing and learned quiet a lot again in just 2 days. Putting my knowledge to use and looking at the script, it all looks fine to me yet it’s giving an error.

-- Trying to make it rain killbricks with a script using instances btw.

while true do
	wait()
local lolpart = Instance.new("Part", game.Workspace)
lolpart.Anchored = false
lolpart.Position = Vector3.new(0,50,0)
lolpart.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		hit.Parent.Humanoid.Health = 0
	end
end)
end

But I did put an end? Wouldn’t that close the “do” from the while loop as it wants? I’m a bit confused and would appreciate someone to explain what’s wrong in my simple script?

you never added an “end” for this

Remove the ) from the end)

1 Like

no don’t do that!
then their connection will be broken

just add an “end” to the last line

1 Like

Wait I didn’t see the touched function, just put a end below the end)

1 Like

Thanks, quick question still relating to this. So is it kinda like a pattern with the ends? like “end” then “end)” then “end” and etc?

let me explain how the end’s in your code work real quick

information
while true do wait()
    lolpart.Touched:Connect(function(hit)
        if hit.Parent:FindFirstChild("Humanoid") then

        end
    end)
end

the first line calls a while loop

all loops end in “end” except for repeat loops
repeat loops end in “until”

while true do
end

for Count = 1, 5, 1, do
end

repeat
until false

now we get to the event connection

lolpart.Touched:Connect(function(hit)
end)

all functions end with “end” as well, but how did we get the “)” after the “end”?
basically “(function” that first part started a beginning parenthesis, and you must end every parenthesis, which is why “end)” is used

if hit.Parent:FindFirstChild("Humanoid") then
end

and if statements also end in “end”

so remember all beginning parenthesis need an end parenthesis(unless you have a string)

1 Like