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

how to have different animations for tool equipped, activated, and deactivated?

this is my first approach:

script.Parent.Equipped:connect(function()
	local Wield = script.Parent.Parent.Humanoid:LoadAnimation(script.Wield)
	local Lunge = script.Parent.Parent.Humanoid:LoadAnimation(script.Lunge)
	local Attack = script.Parent.Parent.Humanoid:LoadAnimation(script.Slash)

	Wield:Play()
end)

script.Parent.Activated:connect(function()
	local Wield = script.Parent.Parent.Humanoid:LoadAnimation(script.Wield)
	local Lunge = script.Parent.Parent.Humanoid:LoadAnimation(script.Lunge)
	local Attack = script.Parent.Parent.Humanoid:LoadAnimation(script.Slash)

	Wield:Stop()
	Lunge:Play()
end)

script.Parent.Activated:connect(function()
	local Wield = script.Parent.Parent.Humanoid:LoadAnimation(script.Wield)
	local Lunge = script.Parent.Parent.Humanoid:LoadAnimation(script.Lunge)
	local Attack = script.Parent.Parent.Humanoid:LoadAnimation(script.Slash)

	Lunge:Stop()
	Slash:Play()
end)

1 answer

✓ Accepted answer

why are you defining them three times in a row, you can just define them outside the function like this

local humanoid = script.Parent.Parent.Humanoid
local Wield = humanoid:LoadAnimation(script.Wield)
local Lunge = humanoid:LoadAnimation(script.Lunge)
local slash = humanoid:LoadAnimation(script.Slash)
local tool = script.Parent
local isWieldPlaying = false

tool.Equipped:Connect(function()
	if Wield and Lunge and slash and not isWieldPlaying then
		isWieldPlaying = true
		Wield:Play()
		wait(Wield.Length)
		isWieldPlaying = false
	end
end)

tool.Activated:Connect(function()
	if isWieldPlaying then
		repeat wait() until isWieldPlaying == false
		Lunge:Play()
		wait(Lunge.Length)
		Lunge:Stop()
		Slash:Play()
		wait(Slash.Length)
		Slash:Stop()
	end
end)

1 comment

0

im very new to scripting so i did that. im sorry. anyways, thank you so much for answering. <3

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