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

can somebody help me make this script so that i can use mouse2 to activate the script?

Asked by 6 years ago
01local tool = script.Parent.Parent --your tool
02local toolActive = false
03local damage = 15
04local duration = 2
05local damagedChars = {}
06 
07local function checkIfDamaged(x)
08    for index, value in pairs(damagedChars) do
09        if value == x then return true end
10    end
11    return false
12end
13 
14local function onTouched(hit)
15    if not toolActive then do return end end
View all 30 lines...
0
nest a Mouse.Button2Down event inside a Tool.Equipped event Gey4Jesus69 2705 — 6y

2 answers

Log in to vote
0
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.

01local tool = script.Parent.Parent --your tool
02local toolActive = false
03local damage = 15
04local duration = 2
05local damagedChars = {}
06local equipped = false
07local mouse = game:GetService('Players').LocalPlayer:GetMouse()
08 
09local function checkIfDamaged(x)
10    for index, value in pairs(damagedChars) do
11        if value == x then return true end
12    end
13    return false
14end
15 
View all 44 lines...
0
Explain the script. yHasteeD 1819 — 6y
Ad
Log in to vote
0
Answered by 6 years ago
Edited 6 years ago
01local player = game:GetService("Players").LocalPlayer
02local mouse = player:GetMouse()
03local tool = script.Parent.Parent
04local CanFire = false
05 
06tool.Equipped:Connect(function()
07   CanFire = true
08end)
09 
10tool.Unequipped:Connect(function()
11   CanFire = false
12end)
13 
14mouse.Button2Down:Connect(function()
15   if CanFire == true then
16      --do code
17   end
18end)

You could also do:

1local player = game:GetService("Players").LocalPlayer
2local mouse = player:GetMouse()
3local tool = script.Parent.Parent
4 
5tool.Equipped:Connect(function()
6   mouse.Button2Down:Connect(function()
7      --do code
8   end)
9end)

But I'm always wary of doing this because I'm not sure how it responds when you unequip. You could test though!

0
Explain the script. yHasteeD 1819 — 6y
0
we were talking in the chat, thats why i didnt Gey4Jesus69 2705 — 6y

Answer this question