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

Help me with this Gui? (SOLVED)

?Hello, I need some help on this gui script. Whenever someone clicks the gui or hits the key "N" the text will change to something else. Here's the script

local screenGui = Instance.new("ScreenGui")
screenGui.Parent = script.Parent

local textButton = Instance.new("TextButton")
	textButton.Parent = screenGui
	textButton.Position = UDim2.new(0, 25, 0, 50)
	textButton.Size = UDim2.new (0, 150, 0, 50)
	textButton.BackgroundColor3 = BrickColor.Black().Color
	textButton.Text = "Hello there, please press n or click me!"
	textButton.TextColor3 = BrickColor.Red().Color
	textButton.TextScaled = true
	textButton.Font = "Legacy"
	textButton.FontSize = "Size24"
	
	textButton.MouseButton1Down:connect(function()
		if key:lower() == "N" then
		textButton.Text = "Thank you for opening me! This is the game instructions! Continue reading!"
		textButton.MouseButton1Down:connect(function()
			if key:lower() == "N" then
				textButton.Text = "This is a sword fight game! Each kill awards you 20 player points!(Continue)"
				if textButton.MouseButton1Down:connect(function()
					if key:lower() == "N" then
						textButton.Text = "Everyone gets the same sword for equality! If they do more damage, there hacking!(Continue)"
						if textButton.MouseButton1Down:connect(function()
							if key:lower() == "N" then
								textButton.Text = "If you see any hacking, please report it to the creator, SirTwoFace and he'll get right to you!(Continue)"
								if textButton.MouseButton1Down:connect(function()
									if key:lower() == "N" then
									textButton.Text = "Now go out there and blox some people!(Continue)"
									if textButton.MouseButton1Down:connect(function()
										if key:lower() == "N" then
											script.Parent.Parent.Remove()
											
										end
									end)	
					      then	end
				              end
						   end
					    end)
					end
				end)
			end)
		end)
	end)

I always get the errors at the ends. I add the ) but then another one says error for saying "Expecting ")" near "end"" when it's already there. Can you help me??

1 answer

✓ Accepted answer

You're going about this all wrong.

key is not defined; it's a nil value.

MouseButton1Down will fire every time a player clicks a GUI, not when they press a key on their keyboard.

Checking multiple times if the key is 'N' is useless. What would end up happening is all those if statements would return true extremely quickly with just a single press of N. You would not have to press N more than once to rotate through those messages.

You need to use the a table to change the text, and the KeyDown event to check if a player presses 'N'.

local messages = {"","","","","","","","",""} --Change to your messages, of course.
local currentMessage = 0
local maxMessage = #messages

local mouse = game.Players.LocalPlayer:GetMouse()

mouse.KeyDown:connect(function(key)
	if key:lower() ~= "n" then return end --Stop everything if the key is not 'n'.

	currentMessage = currentMessage + 1
	if currentMessage > maxMessage then
		currentMessage = 0 
		textbutton.Text = ""
	else
		textbutton.Text = messages[currentMessage]
	end
end)

This method also makes a text button not necessary. Use a text label instead.

2 comments

0

Yeah I was trying to say if they pressed the n key or clicked it :l, but thanks!!!

0

Oh well you can use the same method to use a clicked event just take out line 08.

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