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

how to make it so that when you press dot it prints?

uis = game:GetService("UserInputService")
uis.InputBegan:Connect(function(key)
	if key.KeyCode == Enum.KeyCode.Period then
		print("something")
	end
end)

16 comments

0

this doesnt work btw

0

i know

0

how do i make it work

0

The code looks good, make sure it's a localscript (if you wanted it client-sided) in starterplayerscripts

0

its in a local script and it doesnt work

0

but i don't see the error

0

check line 2, that may be the cause of the error(inputBegan)

0

it works for other keys just not for period

0

post this on the dev forums because i don't know

0

i cant post on devforum

0

that's the only way you can receive help.

0

Bro thats literally the same

0

what?

0

the guy that posted the answer

0

oh

1 answer

✓ Accepted answer

The problem is the dot is already a key to turn right, So it won't do anything, Try this

local contextActionService = game:GetService("ContextActionService")

function onPressed()
	
	print("Pressed!")
	
end

contextActionService:BindAction("print", onPressed, false, Enum.KeyCode.Period)

Also put it in StarterGui

The reason why your script wasn't working is the dot is already a bind action to turn right with userinputservice it can't overwrite the action, So with ContextActionService we are overwriting the bind action of the dot so it will work, Also turn it to true if you want to make a mobile button of it.

8 comments

0

you literally just changed the script

0

Here is a devhub article about ContextActionService https://developer.roblox.com/en-us/api-reference/class/ContextActionService

0

In case you want to learn about contextactionservice

0

This doesn't always work

0

Try putting it in StarterCharacter

0

I already know how to use localscripts, i placed it in startercharacterscripts,startgui, startplayerscripts and all localplayer containers

0

what im saying is that it doesn't always work. i don't know if that's a roblox issue or smth.

0

I might have to post this on the developer forums

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