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

How does the Mouse Button1Down event work?

Asked by 11 years ago

I just created the following script:

01-- Import animation
02local animation = Instance.new("Animation")
03animation.AnimationId = "http://www.roblox.com/Asset?ID=146374944"
04 
05-- Others
06MyMouse = mouse
07MyMouse.Button1Down:connect(playAnim)
08 
09-- Local variables
10local animTrack = nil
11local canPlay = true
12 
13function playAnim(Source)
14    if canPlay then
15        local player = script.Parent.Parent
View all 22 lines...

But it gives me the following Error:

18:32:57.308 - Workspace.Player1.ID [C5].Script:20: attempt to index global 'mouse' (a nil value)

18:32:57.310 - Script 'Workspace.Player1.ID [C5].Script', Line 20

18:32:57.310 - stack end

How can I fix it. Please note the following: -This is a tool -This is supposed to run an Animation in the Humanoid. It works perfectly without MouseClicks

0
local mouse = player:GetMouse() Launderer 343 — 6y

1 answer

Log in to vote
5
Answered by 11 years ago

You're not using any events here! mouse isn't just some magical global variable, you need to get it from somewhere. The mouse object is given as the first argument in the Equipped event of tools.

1script.Parent.Equipped:connect(function(mouse)
2    mouse.Button1Down:connect(function()
3        print("Blockhaak down!")
4    end)
5end)
0
Thanks, you really helped me! (I would Up-vote, but I cant xD) devSparkle 84 — 11y
0
Thanks, you should be able to accept the answer, though. User#11893 186 — 11y
1
Excellent answer! Unclear 1776 — 11y
Ad

Answer this question