I’m trying to make my own drop system, all I need is for the idle animation to stop
Unequipping works fine
You still have to use the :Stop() method even when the script that started the animations has been destroyed
Use Tool.Destroying
function and the rest of the code is up to you.
Could you send the code for the animations? I’d need to see how the code works to see if I could help you
These are for making the animations (server script)
if Module.IdleAnimationID ~= nil then
local IdleAnim = Instance.new("Animation")
IdleAnim.Name = "IdleAnim"
IdleAnim.AnimationId = "rbxassetid://"..Module.IdleAnimationID
IdleAnim.Parent = Tool
end
if Module.EquippedAnimationID ~= nil then
local EquippedAnim = Instance.new("Animation")
EquippedAnim.Name = "EquippedAnim"
EquippedAnim.AnimationId = "rbxassetid://"..Module.EquippedAnimationID
EquippedAnim.Parent = Tool
end
if DictionaryFuncs.GetLength(Module.AttackAnimationIDs) > 0 then
local AttackAnims = Instance.new("Folder")
AttackAnims.Name = "AttackAnims"
AttackAnims.Parent = Tool
for i, v in pairs(Module.AttackAnimationIDs) do
if v ~= nil then
local AttackAnim = Instance.new("Animation")
AttackAnim.Name = i
AttackAnim.AnimationId = "rbxassetid://"..v
AttackAnim.Parent = AttackAnims
end
end
end
These are for playing the animations (local script)
if Module.IdleAnimationID ~= nil then
IdleAnim = Tool:WaitForChild("IdleAnim")
IdleAnim = Humanoid:LoadAnimation(IdleAnim)
table.insert(Animations, IdleAnim)
end
if Module.EquippedAnimationID ~= nil then
EquippedAnim = Tool:WaitForChild("EquippedAnim")
EquippedAnim = Humanoid:LoadAnimation(EquippedAnim)
table.insert(Animations, EquippedAnim)
end
if DictionaryFuncs.GetLength(Module.AttackAnimationIDs) > 0 then
local AttackAnims = Tool:WaitForChild("AttackAnims")
for i, v in pairs(AttackAnims:GetChildren()) do
local AttackAnim = Humanoid:LoadAnimation(v)
AttackAnimations[v.Name] = AttackAnim
end
end
Doesn’t work + no error? Am I doing something wrong?
local Tool = script.Parent
local Event = script:WaitForChild("RemoteEvent")
local UIS = game:GetService("UserInputService")
Tool.Equipped:Connect(function()
UIS.InputBegan:Connect(function(input, gameProcessedEvent)
if input.UserInputType == Enum.UserInputType.Keyboard then
if input.KeyCode == Enum.KeyCode.G then
local Char = script.Parent.Parent
local Hum = Char:WaitForChild("Humanoid")
local Idle = Hum:WaitForChild("Animator"):LoadAnimation(Tool.IdleAnim)
Idle:Stop()
Idle.Stopped:Wait()
Event:FireServer()
end
end
end)
end)
On the local script could you try adding a function that happens upon the tool getting unequipped?
I haven’t seen how your animations are stored so feel free to change it up if it dosent match your style of coding.
Tool.Unequipped:Connect(function() -- Tool unequipping
if IdleAnim then
IdleAnim:Stop()
else
return
end
end)
I’m pretty sure only a Keyboard InputType Has Enum.KeyCode.G try removing this line:
I mainly use it for Checking if the user is typing in chat. If you want to use it. This is how i’d do it
local Tool = script.Parent
local Event = script:WaitForChild("RemoteEvent")
local UIS = game:GetService("UserInputService")
Tool.Equipped:Connect(function()
UIS.InputBegan:Connect(function(input, typing)
if input.KeyCode == Enum.KeyCode.G and typing == false then
local Char = script.Parent.Parent
local Hum = Char:WaitForChild("Humanoid")
local Idle = Hum:WaitForChild("Animator"):LoadAnimation(Tool.IdleAnim)
Idle:Stop()
Idle.Stopped:Wait()
Event:FireServer()
end
end)
end)
Think of it as an example in your case. You want to make a tool dropping system. The player must press G in order to drop the tool. If you are typing chat that has the letter G, it will fire the Keycode event, making you drop the tool when you are typing. gameProcessedEvent will help prevent this.
This might not help fix the no error bug but having gameProcessedEvent helps reduce a future bug.
i’d recommend just unequipping the player’s tool before destroying it. The animation will stop playing before it gets destroyed.
Honestly, just use a .Destroying event. There’s no reason to make code longer for the same result
If it’s a custom tool then disable the animation once the tool is unequipped