Why is EquipTool() not giving the character the tool?

Hi! I am making a hotbar system. I already have an inventory system which you can put the tools in the hotbar. When you equip the tools in the inventory it works, but when you press on the slot in the hotbar it doesnt work even though they use the same script? All the prints fire correctly but it is not giving the character the tool. Please help.

local button = script.Parent
local plr = game.Players.LocalPlayer

local selected = script.Parent:WaitForChild("Selected")
local equipped = script.Parent.Parent.Parent.Frame.Handler.Equipped
local location = script.Parent.Parent.Parent.Frame.Handler.Location

button.MouseButton1Click:Connect(function()
	if plr and plr.Character then
		local character = plr.Character
		if equipped.Value == nil or equipped.Value ~= selected.Value then 
			character.Humanoid:UnequipTools() 
			print("Tool")
			if location.Value == plr.Backpack then
				print("HOT BAR1:".. button:FindFirstChild("Selected").Value.Name)
				

				character:WaitForChild("Humanoid"):EquipTool(selected.Value)
				equipped.Value = selected.Value
				print("Equipping Tool")
			end
		else

			character.Humanoid:UnequipTools()
			equipped.Value = nil
			print("Unequipping tool")
		end
		character.Humanoid:UnequipTools()
	end
end)
1 Like

It looks like you’re trying to compare it with a Value Instance, which I think will not work

The first parameter of the EquipTool() function needs to be an actual Tool Instance, and not a Value

https://developer.roblox.com/en-us/api-reference/function/Humanoid/EquipTool

its an object value so it must be an instance

Wait, is this on a LocalScript…?

yes it is in a local script which is a descendant of player gui

I think that’s why? Equipped Tools in a Local Script can play a bit wonky at times (Which could potentially break the entire script), I think you could try a RemoteEvent to get the Player there instead?

You could just make the tool’s parent the character.

This should work.

You should put a tool inside either Replicated Storage or ServerStorage and then use

character:WaitForChild("Humanoid"):EquipTool(game:GetService("ReplicatedStorage").YourTool)

What you are doing is trying to equip a string value which is not possible.

You could get the tool from replicated storage using Selected.Value like this

character:WaitForChild("Humanoid"):EquipTool(game:GetService("ReplicatedStorage")[selected.Value])

I worked it out now it was because I was equipping a different tool than before so it instantly equips it and unequips it. Also, I did not try and equip a string I equipped an instance in a object value which is a tool.