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

How to fix glitch ? (Animation Idle Staying even after I unequip the sword)

The sword named Nichirin, here the code:

local module = {}
function foundkatanatool(char)
	wait(.1)
	local tool = char:FindFirstChildWhichIsA("Tool")
	if tool then
		local typ = tool:FindFirstChild("Type")
		if typ and typ.ClassName == "StringValue" and typ.Value == "Sword" then
			return true
		end
	end
end
module.EquipNichirin = function(character)
	local model = character:FindFirstChild("SwordModel")
	if model and model:IsA("Model") and character:FindFirstChild("Humanoid") then
		local anim = character.Humanoid:LoadAnimation(script.Idle)
		anim:Play()

		if character.EquippedKatana.Value == false then
			character.HumanoidRootPart.UnSheathe:Play()
			local unsheatheanim = character.Humanoid:LoadAnimation(script.UnSheathe)
			unsheatheanim:Play()
			unsheatheanim:AdjustSpeed(.5)
		end


		character.EquippedKatana.Value = true

		local weld = model.Handle:FindFirstChild("HandleWeld")
		if weld then
			weld.Part0 = character:FindFirstChild("Right Arm")
			weld.C0 = CFrame.new(0, -1, 0) * CFrame.Angles(math.rad(270),math.rad(180),math.rad(90)) * CFrame.Angles(0, math.rad(90), 0)
		end
	end
end

module.UnequipNichirin = function(character)
	local model = character:FindFirstChild("SwordModel")
	if model and model:IsA("Model") and not foundkatanatool(character) and character:FindFirstChild("Humanoid") then
		local anim = character.Humanoid:LoadAnimation(script.Idle)
                anim:Stop()

		local anim = character.Humanoid:LoadAnimation(script.Sheathe)
		anim:Play()
		anim:AdjustSpeed(.8)
		character.EquippedKatana.Value = false

		local weld = model.Handle:FindFirstChild("HandleWeld")
		if weld then
			delay(.12,function()
				if not foundkatanatool(character) then
					weld.Part0 = character:WaitForChild("Torso")
					weld.C0 = CFrame.new(-1, -.1, -1.2) * CFrame.Angles(math.rad(200),math.rad(180),math.rad(90))
				end
			end)
		end
	end
end

1 answer

I would just do this (Btw add a animation Inside of tool):

local tool = script.Parent
local animation = tool.Animation
local AnimationTrack

tool.Equipped:Connect(function()
	local Char = tool.Parent
	local Humanoid = Char.Humanoid
	
	AnimationTrack = Humanoid:LoadAnimation(animation)
	AnimationTrack:Play()
end)

tool.Unequipped:Connect(function()
	AnimationTrack:Stop()
end)

2 comments

0

Sr but I don't get it, wdym by add a animation in inside of tool? The tool already have animation but the animation idle wont stop even when i unequip it (Btw i want to know how to fix the problem but not redo all the code )

0

Sorry to break to ya, but Im not a really skilled scripter, but what I mean add a animation Is that the Idle animation I use needs a animation

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