How to make a script that checks if there is a weapon in Starter Pack already from Replicated Storage and replaces it instead or adding another tool?

I wanted to make a script that checks if there is a tool in the starter pack that comes from Replicated Storage and if so replaces the weapon instead of adding another tool.

Here’s the script I’m using, and I need it modified

local tool = game.ReplicatedStorage.HK416D --Refers “tool” as game.ReplicatedStorage.YourTool. Put your tool name in the ClassicSword.

local player = game.Players.LocalPlayer --finds the script’s parent, the player.

script.Parent.MouseButton1Click:Connect(function() --when clicked, function

tool:Clone() --clones tool

tool:Clone().Parent = player.Backpack --has the cloned tool’s parent the player’s Backpack


I’ve looked all over youtube for the whole day and no methods have worked.

1 Like

Hi! Firstly, please look into formatting code using code blocks. It makes it much easier to read code to help you.

Secondly, If you’re replacing a weapon why do you need to know if it comes from replicatedstorage? Making the weapon un-equip by force then just equipping a new weapon will accomplish the same function regardless of whether or not the tool is from ReplicatedStorage or otherwise.

However, one way to successfully work with your usecase is to just place all of your weapons in a folder in replicatedstorage, then just check to see if the weapon is also in that folder before replacing.

So basically, I want to make a tool giving GUI button that gives one tool at a time meaning they can only have 1 of the guns in their inventory at a time and if they want another on the guns will replace, how would I do that.

1 Like

Remove their current gun then add the new one, I’d say. How you do that will depend on how you implement the system of gun exchange. One such way would be to use the default equip/unequip framework provided by Tool as a class, the other would be to write your own system of equipping and using tools.

If using tools as-is, unequip and destroy the tool you’re wanting to replace, then clone and equip the new tool.

1 Like

Generally what you can do is with whatever script is adding a tool to the backpack, do

if plr.BackPack.tool == nil then
--add tool
1 Like