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

Keydown Script Pulls out Weapon?

So I'm trying to find out how to do a keydown script where when you press Q your wep pulls out base off an animation kind of like sbo weps, and then when you click it swings doing dmg to people. Anyone can tell me how to do it?

1 answer

here is a simple code in how to detect the players mouse, first you need to get the mouse using the :GetMouse() function.

Player = script.Parent.Parent --Finding You / Player
mouse = Player:GetMouse() -- Getting the players mouse

then we will need to create a funtion to dectect the key press/lowering in this case

function onKeyDown(key)
   key = key:lower()
end
mouse.KeyDown:connect (onKeyDown)

finally we define the key we want to lower into the function

   if key == "q" then --"q" Is the Key that will be pressed for this action to work

So are final code would be:

Player = script.Parent.Parent --Finding You / Player
mouse = Player:GetMouse()

function onKeyDown(key)
   key = key:lower()
   if key == "q" then --"q" Is the Key that will be pressed for this action to work
   end
end
mouse.KeyDown:connect (onKeyDown)

This is just a simple code to set you in the right direction, not the full code

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