Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

I have a error In my script that constructs and destructs guis evolving " End "?

Error with the end all the way to the bottom

--if _ Keydown delete and create new Gui 
game:GetService("UserInputService").InputBegan:connect(function(key)
if key.KeyCode == Enum.KeyCode.Tab then
    print 'the key Tab has been pressed'
    local Gui = game.Players.LocalPlayer.PlayerGui:FindFirstChild("One")
    if Gui then
    Gui:Destroy()
    end
end 
------------------------------------------------------------------------------------
game:GetService("UserInputService").InputBegan:connect(function(key)
if key.KeyCode == Enum.KeyCode.Tab then
	player = game.Players.LocalPlayer
	gui = game.Lighting.Two
	gui:Clone().Parent = player.PlayerGui
end
game:GetService("UserInputService").InputBegan:connect(function(key)
if key.KeyCode == Enum.KeyCode.Tab then
	local Gui = game.Players.LocalPlayer.PlayerGui:FindFirstChild("Two")
	if Gui then 
	Gui:Destroy()
	end 
end --ERROR

2 answers

✓ Accepted answer

when you did

(function(key)

you forgot to close the 1st bracket

so....

end) -- line 23

The anonymous functions need ends

Easy mistake.

game:GetService("UserInputService").InputBegan:connect(function(key)
	if key.KeyCode == Enum.KeyCode.Tab then
		print 'the key Tab has been pressed'
		local Gui = game.Players.LocalPlayer.PlayerGui:FindFirstChild("One")
		if Gui then
			Gui:Destroy()
		end
	end 
end)
------------------------------------------------------------------------------------
game:GetService("UserInputService").InputBegan:connect(function(key)
	if key.KeyCode == Enum.KeyCode.Tab then
		player = game.Players.LocalPlayer
		gui = game.Lighting.Two
		gui:Clone().Parent = player.PlayerGui
	end
end)

game:GetService("UserInputService").InputBegan:connect(function(key)
	if key.KeyCode == Enum.KeyCode.Tab then
		local Gui = game.Players.LocalPlayer.PlayerGui:FindFirstChild("Two")
		if Gui then 
			Gui:Destroy()
		end 
	end 
end)

You also don't need multiple functions.

game:GetService("UserInputService").InputBegan:connect(function(key)
	if key.KeyCode == Enum.KeyCode.Tab then

		local player = game.Players.LocalPlayer
		local gui = game.Lighting.Two
		print 'the key Tab has been pressed'
		local Gui = player.PlayerGui:FindFirstChild("One")
		if Gui then
			Gui:Destroy()
		end
		gui:Clone().Parent = player.PlayerGui

		local Gui = player.PlayerGui:FindFirstChild("Two")
		if Gui then 
			Gui:Destroy()
		end 
	end 
end)
That was thrown together.

Good Luck!

This discussion is preserved as it was. New answers, comments, and votes are closed.