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

How to i make that if someone left clicks their mouse they punch on roblox studio?

if you can can you send me the code of it

2 comments

0

Request.

0

but you make an animation, and when you do mousebutton1down:Connect(fucntion), you just defien the animation and play it

1 answer

Hello,

There are a variety of ways to check for a player’s click, however the best option is to use UserInputService. However it only works in LocalScripts, so that’s what the script will need to be.

Basically you check when a player begins input (e.g. starts holding down a key), then check what type of input they are doing.

local UserInputService = game:GetService("UserInputService")
local Tool = script.Parent

UserInputService.InputBegan:Connect(function(InputObject)
    if InputObject.UserInputType == Enum.UserInputType.MouseButton1 then
        -- play animation
    end
end)

How it works is you use the LoadAnimation method found in Humanoid, giving it the Animation object that has the AnimationId and other data. This method returns an AnimationTrack object that you can use to control the animation – play it, stop it etc.

Here’s an example:

local Player = game.Players.LocalPlayer -- this also only works in LocalScripts
local Character = Player.Character
local Humanoid = Character:WaitForChild("Humanoid")

local Animation = Instance.new("Animation") -- create a new animation object
Animation.AnimationId = "rbxassetid://00000" -- put your animation id over the zeroes

local Track = Humanoid:LoadAnimation(Animation)
Track:Play()
Track:Stop()

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