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..
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.
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)