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 10 years ago

I just created the following script:

-- Import animation
local animation = Instance.new("Animation")
animation.AnimationId = "http://www.roblox.com/Asset?ID=146374944"

-- Others
MyMouse = mouse
MyMouse.Button1Down:connect(playAnim)

-- Local variables
local animTrack = nil
local canPlay = true

function playAnim(Source)
    if canPlay then
        local player = script.Parent.Parent
        canPlay = false
        animTrack = player.Humanoid:LoadAnimation(animation) -- Load animation into Humanoid
        wait(2)
        canPlay = true
        end 
        animTrack:Play() -- Start the animation
    end

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 — 5y

1 answer

Log in to vote
5
Answered by 10 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.


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

Answer this question