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

How can i make this script work from Button1Down to Keydown?

i am trying to make this work on a key... For example C

Could anyone help me?

local Player = game.Players.LocalPlayer

script.Parent.Selected:connect(function(m) 
m.Button1Down:connect(function() 
	Player.Character.Scripts.Chip.RKick:FireServer()
end) 
end)

2 answers

✓ Accepted answer

Use UserInputService, it Fires when any Input is received from either the Mouse or Keyboard and more. It provides an argument holding the Input information, which in this case we can place into a Conditional for C. It would look something like this

local UserInputService = game:GetService("UserInputService")

UserInputService.InputBegan:Connect(function(InputObject)
   if (InputObject.UserInputType == Enum.UserInputType.Keyboard) then
      if (InputObject.KeyCode == Enum.KeyCode.C) then 
         --// Code
      end
   end
end)

Hope this helps, read up on UserInputService as it can be of great use. Remember to accept this answer if it helps!

1 comment

0

Thank you that works!

Are you trying to fire server whenever you press the button C? Then I think I have the solution:

local uis = game:GetService("UserInputService") 

uis.InputBegan:Connect(function(Input)

if Input.KeyCode == Enum.KeyCode.C then

	Player.Character.Scripts.Chip.RKick:FireServer()

end)

1 comment

0

Works as well thanks!

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