✓ Accepted answer
##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.
2 comments
Try putting prints after every line so you know when it stops working
Okay