Your first end on the second function acts like it's enclosing an anonymous function, when really, it's closing (at least, trying to) the if statement.
If you remove the parenthesis for the if statement, you'll solve the problem, but you will encounter more errors because hg is local in the first anonymous function. Remove local, so hg will fetch the variable from the first function.
Also, you don't need the l:connect(function(mouse)... end), because you are basically putting an input inside of an input function, when you only need one input (the mouse; mouse.KeyDown:connect(function(key)... end)). Plus, l:connect(function(mouse)... end) doesn't have an event to trigger (such as Touched, MouseClick, etc).
EDIT
I've edited the indentations so it would be easier to see.
local l = script.Parent
local Mouse = game.Players.LocalPlayer:GetMouse()
l.Touched:connect(function(hit)
for _,v in pairs(game.Players:GetChildren()) do
hg = v.Character
local h = script.Parent.ScreenGui
spawn(h).Parent = hg.PlayerGui
end
end)
Mouse.KeyDown:connect(function(key)
if key == "l" then
hg:MoveTo(Vector3.new(-15.3, 1.191, -99.5))
end
end)
NOTE: I'm not familiar with ROBLOX-specific functions, but according to the Function Dump/Functions that are specific to ROBLOX page, the spawn() method's argument (anything in the paranthesis) was for functions, not objects (spawn(h); h is referring to an object, which is script.Parent.ScreenGui.
If you want to place h in hg.PlayerGui, do this instead:
h.Parent = hg.PlayerGui
I wasn't entirely sure what your script was meant to do, so just refer to this to fix some of its errors.
2 comments
Can you add the script? I can barely, Understand half of what you mean. It would be easier to understand with the script along with -- On Areas I did wrong, and Why.
All right, I've edited the parts where I believe the errors are at, except for the spawn() function.