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

My script won't register "T" being clicked?

Asked by 8 years ago
game:GetService("UserInputService").InputBegan:connect(function(key)
    if key == Enum.KeyCode.T then
        print("Player " .. game.Players.LocalPlayer .. " has pressed space!")
    end
end)

No output. It says pressed space since it was my original intention but then I tried T and it didn't work sooo..

0
Try putting prints after every line so you know when it stops working docrobloxman52 407 — 8y
0
Okay mechmasterfire 50 — 8y

1 answer

Log in to vote
2
Answered by
M39a9am3R 3210 Moderation Voter Community Moderator
8 years ago

Problem

Your problem is, you're treating "key" as KeyCode while this is not the case. The first argument provided to the InputBegan function is a table value which holds Delta, KeyCode, Position, UserInputType, and UserInputState. The element you need to utilize is the KeyCode for your script.

You also tried to connect a userdata value, the player value (LocalPlayer), into a string. You want to connect a string into a string, or a string and a number to make that into a string. All you simply have to do is add .Name to the end of LocalPlayer. I do not know how I missed that.


Final Solution

This is a fairly easy fix as all you have to do is add .KeyCode to the end of "key". As well as add .Name to the end of "LocalPlayer".

game:GetService("UserInputService").InputBegan:connect(function(key)
    if key.KeyCode == Enum.KeyCode.T then
        print("Player " .. game.Players.LocalPlayer.Name .. " has pressed space!")
    end
 end)

If this solution did not work please post the error, if any, in the comments.

Did this answer your question? Hit the accept answer button! If it only helped please hit the upvote button. Any questions, just post in the comments below and I will get back to you soon.
0
Okay. Let me see mechmasterfire 50 — 8y
0
Players.Player.Backpack.Testinggg:3: attempt to concatenate field 'LocalPlayer' (a userdata value) This is a local script.. Mind telling me this real quick? mechmasterfire 50 — 8y
0
Forget I am just going to put a few parents mechmasterfire 50 — 8y
Ad

Answer this question