I’m working on a script right now, I’ve already got the animations.
I just am trying to of course have them play by clicking on left mouse.but I’m wondering how I’d make the anim play in response to pressing on m1
You should use UserInputService.
I don’t understand the question, is the problem the keybind or the animation?
Im new to this sorry.
I know how to use Get mouse and the enum stuff to get the Leftclick.
I just dont know how to have the animation play afterwards
I think this is what you need:
Well, you have the player pressing down on the LMB being detected already from what I’ve gathered, so from there it is very simple.
First you need to make sure your animation is an actual “Animation” instance, from there all you need to use is Humanoid:LoadAnimation
in order to prepare the animation, then play it accordingly.
Example:
local Animation = Humanoid:LoadAnimation(--[[animation instance]])
Animation:Play()
Oops i guess I dont know how to get the mouse, Could you help me with that too? lol
Let’s use UserInputService over GetMouse since I find it more adaptable that way.
First, insert a local script into StarterGui like so:
Now the coding begins, let’s first fetch UserInputService, and connect a function to InputBegan. All that we’re doing is listening for when the player makes an input of ANY kind.
local userinput = game:GetService("UserInputService")
userinput.InputBegan:Connect(function(input,gameProcessed)
end)
Now let’s sort out game processed events (whatever those may be) to avoid an overabundance of inputs being checked further:
local userinput = game:GetService("UserInputService")
userinput.InputBegan:Connect(function(input,gameProcessed)
if not gameProcessed then
end
end)
Then, we need to make sure that the input.UserInputState
is an Enum.UserInputState.Begin
, otherwise whenever a player clicks the left mouse button the function will fire twice.
local userinput = game:GetService("UserInputService")
userinput.InputBegan:Connect(function(input,gameProcessed)
if not gameProcessed then
if input.UserInputState == Enum.UserInputState.Begin then
end
end
end)
Finally we can round it all off by verifying that input.UserInputType
is an Enum.UserInputType.MouseButton2
local userinput = game:GetService("UserInputService")
userinput.InputBegan:Connect(function(input,gameProcessed)
if not gameProcessed then
if input.UserInputState == Enum.UserInputState.Begin then
if input.UserInputType == Enum.UserInputType.MouseButton2 then
print("Left Click!")
end
end
end
end)