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

What is wrong with my function onSwing?

Asked by 9 years ago

I didn't think this would work, but I don't know any other way... How can i get it to play the animation when it is swung? Here is my script

function onEquip()
local animation = script.Slash

print("loading")
local plyr = script.Parent.Parent.Parent.Name
print(plyr)
local char = workspace[plyr]
local anim = char.Humanoid:LoadAnimation(animation)
print("loaded")
function onSwing()
    print("swinging")
anim:Play()
end
print("swung")
end
script.Parent.Equipped:connect(onEquip)
script.Parent.MouseButton1Down:connect(onSwing)

MouseButton1Down is not a valid member of Tool Please help!!! Thank you!!!

2 answers

Log in to vote
1
Answered by
1waffle1 2908 Trusted Badge of Merit Moderation Voter Community Moderator
9 years ago

script.Parent.Parent is Backpack and not the tool. The Backpack doesn't click.

MouseClick is also an event for ClickDetectors only. Mouse.Button1Down is for tools.

script.Parent.Equipped:connect(function(mouse)
    mouse.Button1Down:connect(function()

    end)
end)
0
That didn't work, it says MouseButton1Down is not a valid member of Tool yogipanda123 120 — 9y
Ad
Log in to vote
1
Answered by
rexbit 707 Moderation Voter
9 years ago

MouseButton1Down is a Mouse event, you can access the mouse through the onEquip Function.

function onEquip(mouse)
local animation = script.Slash

print("loading")
local plyr = script.Parent.Parent.Parent.Name
print(plyr)
local char = workspace[plyr]
local anim = char.Humanoid:LoadAnimation(animation)
print("loaded")
function onSwing()
    print("swinging")
anim:Play()
end
print("swung")
end
script.Parent.Equipped:connect(onEquip)
mouse.MouseButton1Down:connect(onSwing)

Answer this question