Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

KeyDown won't work? (UNSOLVED)

Asked by 9 years ago

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

Log in to vote
0
Answered by
tumadrina 179
9 years ago

you need to get the mouse

m=game.Players.LocalPlayer:GetMouse()

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

0
The error isn't there anymore, but the gui won't appear. GreekGodOfMLG 244 — 9y
Ad

Answer this question