Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
KOK_E 12
5 years ago

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

Log in to vote
1
Answered by
Ziffixture 6913 Moderation Voter Community Moderator
5 years ago
Edited 5 years ago

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!

0
Thank you that works! KOK_E 12 — 5y
Ad
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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)

0
Works as well thanks! KOK_E 12 — 5y

Answer this question