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

Play an animation if a player holds down left mouse button with a tool for a certain amount of time?

Asked by
trapiz 4
4 years ago

I want to implement a multi-attack system for a melee weapon, basically if you just tap the left mouse button you will do a light attack, and if you hold down the left mouse button for, say, a second, it will do a heavy attack. Since I'm using a tool, I would prefer to use tool.Activated, but I'm open to other solutions.

2 answers

Log in to vote
0
Answered by 4 years ago

Use the mouse. You can get the mouse by getting the player (in this case it will be the Parent of the tool) and the :GetMouse() function.

local Count = 0
local up = false


local player = game.Players:GetPlayerFromCharacter(script.Parent)
local mouse = player:GetMouse()
mouse.Button1Down:Connect(function()
    repeat
        Count = Count + 1
    until up = true
end)

mouse.Button1Up:Connect(function()
    if Count <= 1 then
        --short blast code here
    else
        --long blast code here
    end
end)
0
put this in the tool User#29913 36 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

Use MouseButton1Click for the light attack and for the heavy attack, use MouseButton1Down as the player would need to hold the left mouse for a heavy attack. Inside the MouseButton1Down add a wait of (1) or 2 and then write the script for the heavy attack.

0
these are for buttons not mouse User#29913 36 — 4y

Answer this question