See Im trying to make it when you touch this brick, the gui that is in the brick goes into player gui, then when you Press 'l' It sends you to certain coordinates... But it has an error.
The error is shown to you in the script
local l = script.Parent l.Touched:connect(function(hit) for _,v in pairs(game.Players:GetChildren()) do local hg = v.Character local h = script.Parent.ScreenGui Spawn(h).Parent = hg.PlayerGui end end) l:connect(function(mouse) mouse.KeyDown:connect(function(key) if key == "l" then hg:MoveTo(Vector3.new(-15.3, 1.191, -99.5)) end) -- Right here it says Expected identifier, got ')' end) end end)
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() -- Mouse variable (this is where the LocalPlayer's mouse is located) l.Touched:connect(function(hit) for _,v in pairs(game.Players:GetChildren()) do hg = v.Character -- Removed "local," because "hg:MoveTo..." was trying to access the variable, but it was stuck within its code block. local h = script.Parent.ScreenGui spawn(h).Parent = hg.PlayerGui -- See "NOTE" end end) Mouse.KeyDown:connect(function(key) -- Your mouse is already an input. Why need another? (Referring to your l:connect(function(mouse)... end)) if key == "l" then hg:MoveTo(Vector3.new(-15.3, 1.191, -99.5)) end -- "end" for your "if" statement; doesn't need a closed parenthesis, since there's no other opened parenthesis that needs to be closed 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.