Custom inventory and unequipping tools

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.

image

(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)
3 Likes

I don’t have a solution for this, however you can also use the Roblox Backpack System and check it, creating frames in UI replicating it. This might make your system more straightforward, something you can consider.

1 Like

You should create Gui with slots 1-9 or smth and then use player’s backpack system, also it’s very important to bind your block or smth to slot it goes to

When you have those gui, then if key is pressed check if slot.Item is truth and then equip it via roblox tool system by parenting tool to player’s character

I’m not planning to use the backpack system because I will be adding more slots in a different ui (similar to minecraft). You can’t sort items with the default backpack system. I just want to know if there are any ways to stop animations or send a signal to the tool to stop the animation before unequipping it.

Edit: I could use the default roblox inventory because it does allow for sorting but not in the way I want.

1 Like

you pretty much can, simply disable toolbar and equip/dequip tools manually by script by parenting them to the right place, you can create your custom toolbar then and connect inputs to specific slots, and then detect what tool is inside, soo you can equip right one

1 Like

I could make that work but I already got my system working mentioned at the top of the initial post.

1 Like