Forcing a tool to be equipped while they already have one equipped bug?

If they have a tool equipped, and I force another tool to be equipped, it equips them both at the same time.

local FruitTool = game.ServerStorage.Tool:Clone()
FruitTool.Parent = character

I might be super dumb, but is there a work around this weird glitch?

When a character has a tool equipped, it is in their character in workspace.
When they don’t, it is in Players>Player>Backpack.

You could try checking:

if character:FindFirstChildWhichIsA("Tool") then
   -- either move the tool that is equipped to the backpack or move that tool that is trying to be equipped to the backpack
end

or

if not character:FindFirstChildWhichIsA("Tool") then
     local FruitTool = game.ServerStorage.Tool:Clone()
     FruitTool.Parent = character
else
     local FruitTool = game.ServerStorage.Tool:Clone()
     FruitTool.Parent = player.Backpack -- assuming you have a player variable somewhere, if not, use PlayerService:GetPlayerFromCharacter(character)
end

Anyone correct me if I’m wrong, as I’m not the best when messing with Player stuff

The “glitch” happens because you’re setting the parent of the tool directly into the character, without checking if there is already a tool. It might be confusing because when a tool is on the ground and has a Handle (so it can be picked up), when a character does pick it up, Roblox automatically detects and unequips any other tools. The same does not happen when you set the parent of a tool to the character.

2 Likes

Yeah I assumed if I force put the tool into the character roblox would automatically detect any other tool and unequip it :confused:

Yeah, it’s confusing, but you always gotta know that your scripts are your problem, and Roblox only checks stuff with their own services.
Also; some more things I noted is that you’re storing the tool directly in ServerStorage. Maybe try creating a folder to separate individual tools, for organization. And use a variable to store ServerStorage as it is used more than once

e.g:

local ServerStorage = game:GetService("ServerStorage") -- always use :GetService() instead of dot, don't ask me why, it's just better and more common

local fruitTools = ServerStorage.Tools.Fruits

if not character:FindFirstChildWhichIsA("Tool") then
     local FruitTool = fruitTools.Tool:Clone()
     FruitTool.Parent = character
else
     local FruitTool = fruitTools.Tool:Clone()
     FruitTool.Parent = player.Backpack -- assuming you have a player variable somewhere, if not, use PlayerService:GetPlayerFromCharacter(character)
end
1 Like

Yeah, I will get to that part. Just doing system making right now before I get into that stuff.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.