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

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

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

2 comments

0

Try putting prints after every line so you know when it stops working

0

Okay

1 answer

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

3 comments

0

Okay. Let me see

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?

0

Forget I am just going to put a few parents

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