Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

What is wrong with my function onSwing?

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

✓ Accepted answer

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)

1 comment

0

That didn't work, it says MouseButton1Down is not a valid member of Tool

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.