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

Trying to open a shop with a key pressed. Not working, and no errors however. tips?

wait()
Player = game.Players.LocalPlayer
Mouse = Player:GetMouse()


ScreenGui =script.Parent.Parent
RobuxFrame = ScreenGui.RobuxFrame
MainFrame = ScreenGui.MainFrame
MedicineFrame = ScreenGui.MedicineFrame
ArmorFrame = ScreenGui.ArmorFrame
UpgradeFrame = ScreenGui.UpgradeFrame
WeaponFrame = ScreenGui.WeaponFrame

Medicine = ScreenGui.Medicine
Armor   = ScreenGui.Armor
Robux  = ScreenGui.Robux  
Weapons   = ScreenGui.Weapons
Upgrades = ScreenGui.Upgrades



RobuxFrame.Visible = false
MainFrame.Visible = false
MedicineFrame.Visible = false
ArmorFrame.Visible = false  
UpgradeFrame.Visible = false 
WeaponFrame.Visible = false 

Medicine.Visible = false 
Armor.Visible = false 
Robux.Visible = false  
Weapons.Visible = false   
Upgrades.Visible = false


function PressQ(key)
	if (key == "q") 
		
		RobuxFrame.Visible = false
		MainFrame.Visible = true
		MedicineFrame.Visible = false
		ArmorFrame.Visible = false  
		UpgradeFrame.Visible = false
		WeaponFrame.Visible = false
	
		Medicine.Visible = true 
		Armor.Visible = true 
		Robux.Visible = true  
		Weapons.Visible = true   
		Upgrades.Visible = true	

	end
end

1 answer

✓ Accepted answer

Hi there,

Your aim currently would be to get the player's key press. However, you seem to be using a function which doesn't have a trigger...Additionally, your current method is deprecated in favour of a new method of getting the player's key pressed. Here's the new method:

Using UserInputService, change your keypress function to this:

function onKeyPress(inputObject, gameProcessedEvent)
	if inputObject.KeyCode == Enum.KeyCode.Q then
		 RobuxFrame.Visible = false
	        MainFrame.Visible = true
	        MedicineFrame.Visible = false
	        ArmorFrame.Visible = false  
	        UpgradeFrame.Visible = false
	        WeaponFrame.Visible = false
	
	        Medicine.Visible = true 
	        Armor.Visible = true 
	        Robux.Visible = true  
	        Weapons.Visible = true   
	        Upgrades.Visible = true 
	end
end
 
game:GetService("UserInputService").InputBegan:connect(onKeyPress)

If you would like more information on this new way of key pressing click the following link below. http://wiki.roblox.com/index.php?title=Keyboard_input

Also, here is the link to the deprecated method. Avoid this link if it confuses you. http://wiki.roblox.com/index.php?title=Keyboard_input_(deprecated)

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