Tool Disappears Instantly on Unequip

I’m working on a katana tool, and I’m trying to create a smooth equip/unequip system with custom animations. My issue is that when I unequip the katana, it disappears immediately, which I know is due to how Roblox handles tools by default.

What I’m trying to achieve:

  • When the katana is equipped, I want it to play an equip animation, change the transparency of the katana model in the character’s hand (see the video for reference), and then switch to an idle animation.
  • When unequipped, I want it to play the unequip animation first, hide the katana after the animation finishes, and revert back to the character’s base idle animation.

Code that is inside the katana tool model

local player = game.Players.LocalPlayer
local rs = game:GetService("ReplicatedStorage")
local animsFolder = rs:WaitForChild("Animations")

repeat wait() until player.Character
local char = player.Character or player.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")

local idleTrack
local idleAnim = animsFolder:WaitForChild("Idle")
local baseIdleAnim1 = animsFolder:WaitForChild("BaseIdle1")
local baseIdleAnim2 = animsFolder:WaitForChild("BaseIdle2")
local equipAnim = animsFolder:WaitForChild("Equip")
local unequipAnim = animsFolder:WaitForChild("Unequip")

local tool = script.Parent
local equipped = false

local function playIdleAnimation()
	idleTrack = hum:LoadAnimation(idleAnim)
	idleTrack.Looped = true 
	idleTrack:Play()
end

tool.Equipped:Connect(function()
	char.Animate.idle.Animation1.AnimationId = idleAnim.AnimationId
	char.Animate.idle.Animation2.AnimationId = idleAnim.AnimationId

	local equipTrack = hum:LoadAnimation(equipAnim)
	equipTrack:Play()

	task.spawn(function()
		task.wait(.7)
		char:WaitForChild("KatanaModel").Blade.Transparency = 1
		tool.Blade.Transparency = 0
	end)

	equipTrack.Stopped:Wait()
	playIdleAnimation()
	equipped = true
end)

tool.Unequipped:Connect(function()
	if idleTrack then
		idleTrack:Stop()
		idleTrack = nil
	end

	local unequipTrack = hum:LoadAnimation(unequipAnim)
	unequipTrack:Play()

	task.spawn(function()
		task.wait(1.7)
		char:WaitForChild("KatanaModel").Blade.Transparency = 0
		tool.Blade.Transparency = 1
	end)

	unequipTrack.Stopped:Wait()

	char.Animate.idle.Animation1.AnimationId = baseIdleAnim1.AnimationId
	char.Animate.idle.Animation2.AnimationId = baseIdleAnim2.AnimationId
	equipped = false
end)

The problem:

  • The katana disappears immediately when unequipping, but I want it to remain visible until the unequip animation completes.
  • I want to control when the katana model becomes visible/invisible using transparency, so I can create a smoother equip/unequip process.

I want to achieve similar effect as Ro-Ghoul’s weapon system has (talking about animations).
Thanks in advance for any help!

Reference:

2 Likes

I tested your code, and nothing seems to be wrong, everything is timed correctly so have you tried using delay like this?

delay(1.7,function()
	char:WaitForChild("KatanaModel").Blade.Transparency = 0
	tool.Blade.Transparency = 1
end)

and yes, don’t worry, it will not block your code.

The script works indeed, the problem is that when you unequip the katana, it disappears and then plays the animation, I can’t change that because that’s how roblox handles tools, the question is what should I use instead of the roblox’s .Equipped event? or how can I make my own custom tool system

1 Like

There’s nothing wrong with your current script, I have tested it, and the animation plays first then the tool disappears.

1 Like

I think that’s how Roblox normally handles tools, because if you put a handle in a tool and equip it, it shows up immediately, but when you unequip, it first hides it then plays the animation

1 Like

I never said code is not working or something, I want to first play the unequip animation and then make the katana disappear (please see the video)

1 Like

And as I said though, the code works correctly on my end (the animation plays first then after 1.7 seconds the sword disappear.

1 Like

Yes, I know that and I stated that in the post

I want anything that will make it to remain visible until the unequip animation completes.

1 Like

So when you press 1 (unequip the tool) it plays the animation and only then the katana disappears from hand?

1 Like

image
There is no katana while playing the animation.


Here’s a video from my end

Contact me on discord if you have time, it may be animation thing :sob:
begi.dll

Sadly, the only solution you can do, is to create your own backpack system.

How could I manage the attacking or even attachments of the weapons?

I’m sure you will find helpful videos on YouTube.

So, my guess is you must create a Model Of The Katana and weld it to the players hand, and when the animation is over, delete it

That sounds good, I’ll try it.

UPD: that worked, thanks!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.