Edit: I ended just using task.wait(1/9999999999)
instead of wait(), which might still give it a delay but it’s unnoticeable.
I am making a custom inventory system for my survival game. I am having trouble stopping animations for the tools I am unequipping. I have an equip function where it checks if there are any tools being held, to unequip them, and then give the player the desired tool. Since I’m using a custom system, I disabled the default Roblox backpack. When I use the :UnequipTools() function, it will delete my tools. I had to arrange this code in a way so that didn’t happen. I tried using Wait() (you can see it commented out) which worked, but it gave a delay in my code and is not the smoothest. I have tried to use tool.Unequipped:Connect(function), but it wouldn’t get called because tool is parented under the player. These tools are using the defualt roblox tool object, not using any custom scripted tools.
How would I be able to unequip tools without deleting them from the inventory or stop the idle animations?
The inventory is set up through folders housed under the client.
(the other tools in the videos don’t have any code inside them)
What the problem looks like:
What it’s supposed to look like (this is with the commented out “wait()”
Equip function (in serverscript service)
equipEvent.OnServerEvent:Connect(function(player,slotName)
local inventoryFolder = player.Inventory
local slotfolder = inventoryFolder:FindFirstChild(slotName)
if player.Character then
local character = player.Character
local humanoid = character:WaitForChild("Humanoid")
if slotfolder:FindFirstChildWhichIsA("Tool") then
if character:FindFirstChildWhichIsA("Tool") then
local tool = character:FindFirstChildWhichIsA("Tool")
humanoid:UnequipTools()
--wait()
tool.Parent = tool.ToolSettings.Slot.Value
end
local item = slotfolder:FindFirstChildWhichIsA("Tool")
item.ToolSettings.Slot.Value = slotfolder
item.Parent = character
else
if character:FindFirstChildWhichIsA("Tool") then
local tool = character:FindFirstChildWhichIsA("Tool")
humanoid:UnequipTools()
--wait()
tool.Parent = tool.ToolSettings.Slot.Value
end
end
end
end)
Tool code
--//Tool//--
local ContextActionService = game:GetService("ContextActionService")
local UserInputService = game:GetService("UserInputService")
local Players = game:GetService("Players")
local tool = script.Parent
local hitbox = tool.Hitbox
local ToolSettings = tool.ToolSettings
local config = tool.Configuration
local actionEvent = tool.Action
local damage = config.Damage
local speed = config.Speed
local blockAnim = config.Block
local idleAnim = config.Idle
local swing1Anim = config.Swing1
local swing2Anim = config.Swing2
--Misc
local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local canswing = true
local canparry = true
local idle
local swing
local parry
local function equipAnim()
if not idle then
local humanoid = character.Humanoid
idle = humanoid.Animator:LoadAnimation(idleAnim)
end
idle:Play()
end
local function unequipAnim()
if idle then
idle:Stop()
idle = nil
end
end
tool.Equipped:Connect(equipAnim)
tool.Unequipped:Connect(unequipAnim)