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: