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

KeyDown won't work? (UNSOLVED)

Hey, I have a local script where this makes a screenGui and a textButton and also if the players press Z, then the text of the textButton will change. Here's the script.

--Made By SirTwoFace











local screenGui = Instance.new("ScreenGui")
local textButton = Instance.new("TextButton")

screenGui.Parent = StarterGui
textButton.Parent = screenGui

textButton.Size = UDim2.new(0, 100, 0 , 200)
textButton.Position = UDim2.new(0, 500, 0 , 500)
textButton.Font = "Legacy"
textButton.BackgroundColor3 = BrickColor.Red().Color
textButton.TextColor3 = BrickColor.Gray().Color
textButton.Text = "Press Z!"


m.KeyDown:connect(function(key)
	if key == "z" then
		textButton.Text = "Thank you for pressing Z!"
		wait(5)
		textButton.Text = "Bye!"
		wait(5)
		textButton.Parent:Remove()
	end
end)

I get a error at line 27 (or where m.KeyDown:connect(function(key) is. It's saying i'm calling M, a nil object. Help would me great!

1 answer

you need to get the mouse

m=game.Players.LocalPlayer:GetMouse()

if you put that at the top, you shouldn't get that error

1 comment

0

The error isn't there anymore, but the gui won't appear.

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