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

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

Asked by 5 years ago

if you can can you send me the code of it

0
Request. tonyv537 95 — 5y
0
but you make an animation, and when you do mousebutton1down:Connect(fucntion), you just defien the animation and play it tonyv537 95 — 5y

Closed as Not Constructive by gitrog, Void_Frost, alphawolvess, and green271

This question has been closed because it is not constructive to others or the asker. Most commonly, questions that are requests with no attempt from the asker to solve their problem will fall into this category.

Why was this question closed?

1 answer

Log in to vote
0
Answered by 5 years ago

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 theLoadAnimation 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()
Ad