Answered by
6 years ago Edited 6 years ago
You can use the :GetMouse()
function of local player
to get the mouse class of player. Then use the Button2Down
event of mouse to get the right-click input from user.
01 | local tool = script.Parent.Parent |
02 | local toolActive = false |
05 | local damagedChars = { } |
07 | local mouse = game:GetService( 'Players' ).LocalPlayer:GetMouse() |
09 | local function checkIfDamaged(x) |
10 | for index, value in pairs (damagedChars) do |
11 | if value = = x then return true end |
16 | local function onTouched(hit) |
17 | if not toolActive then do return end end |
18 | local Humanoid = hit.Parent:FindFirstChildOfClass( "Humanoid" ) |
19 | if Humanoid and not checkIfDamaged(Humanoid.Parent.Name) then |
20 | Humanoid:TakeDamage(damage) |
21 | table.insert(damagedChars, Humanoid.Parent.Name) |
25 | local function onActivated() |
26 | if not equipped then do return end end |
27 | if toolActive then do return end end |
28 | toolActive = true ; wait(duration); toolActive = false |
37 | local function unequip() |
41 | script.Parent.Touched:Connect(onTouched) |
42 | mouse.Button 2 Down:Connect(onActivated) |
43 | tool.Equipped:Connect(equip) |
44 | tool.Unequipped:Connect(unequip) |