The idea behind dequipping an armour piece(My cloning of items is somehow wrong?)

Quite recently I’m having a bit of a problem with my armor service script. Equipping the armor is easy enough to do and changing its stats of it is just a matter of getting the string value of the armor, but I’m having an issue understanding how I would get rid of the armor weld and give back the armor tool when a player decides to equip another armor piece.

For context, my armor service script works via 2 folders
Armor model and Armor tool. when a player activates a tool (that is an armor tool) it activates a remote function that determines the type of armor (head, chest plate, etc) and the name of that armor. From there depending on the name of the armor the script will give the corresponding bonuses and weld that armor piece to that character (as well as destroy the armor tool). Any help would be appreciated

1 Like

same thing as equipping a weapon ( without Tool from roblox)

i made a system where when you press R and equip a sword, it will create a local variable that creates a instance.new motor6d and will attach to the right hand of the player character, for example, however when i press R again it will unequipp, checking if the motor6d exists, if exists then it will call variable:Destroy()

calling destroy will prevent multiples welds or motor6d

if you wish to equip another equipment, then you only need to destroy the old weld attached to the player or whatever

that’s my main issue, I do not know how to find whether a weld exists before. I tried using IsADescendant, but it simply doesn’t remove the weld. My issue is more on how to do the code rather than the theoretics. Thanks for reconfirming my idea though!

If anyone needs my code here it is:

Local Script

--Sigil
local tool = script.Parent
local RE = game:GetService("ReplicatedStorage")
local ArmorEvent = RE.ArmorEvent
local name = "Helm"
local Atype = "Head"
tool.Activated:Connect(function()
	ArmorEvent:FireServer(name,Atype)
end)

Script

local RE = game:GetService("ReplicatedStorage")
local ArmorEvent = RE.ArmorEvent
local ArmorModel = RE.ArmorModel
local ArmorTool = RE.ArmorTool

ArmorEvent.OnServerEvent:Connect(function(plr,name,Atype)
	print(name)


	if Atype == "Head" then 
	
			
		for i, v in pairs(plr.Character:GetChildren()) do 
			if v.Name == name then
v:Destroy()	
			end	
			
		
			


				
				if name == "Helm"   then 
				plr.Character:WaitForChild("Humanoid").WalkSpeed = 3
				local HelmModel = RE.ArmorModel:WaitForChild("Head").Helm:Clone()
				local char = plr.Character
				local head = char.Head

				HelmModel.Parent = char
				HelmModel:SetPrimaryPartCFrame(head.CFrame)

				local weld = Instance.new("WeldConstraint",HelmModel.PrimaryPart)
				weld.Part0 = head
				weld.Part1 = HelmModel.PrimaryPart
			else if name ~=  "Helm" then
					--Dequipping		
				end
			end	
				end	

			if name == "Sigil" then
			
			plr.Character:WaitForChild("Humanoid").WalkSpeed = 13
			
			local sigilModel = RE.ArmorModel:WaitForChild("Head").Sigil:Clone()
				local char = plr.Character
				local head = char.Head
				
				sigilModel.Parent = char
				sigilModel:SetPrimaryPartCFrame(head.CFrame)
				
				local weld = Instance.new("WeldConstraint",sigilModel.PrimaryPart)
				weld.Part0 = head
				weld.Part1 = sigilModel.PrimaryPart
				end	
			
		
	end
	end)


	

If you have equip logic, then the inverse or just a simple destroy is the unequip logic. For example, the RPG experience I work on allows players to equip trophies (parts of a defeated enemy), so the same essence as equipping armour. I have guarantees about this trophy:

  • The trophy will always be a child of a character.
  • The trophy will always be a Model.
  • The trophy will always be named Trophy.
  • The trophy will always have a weld parented to it.

From there, it’s simple: destruction is my unequip. The destruction will break the weld and remove the trophy itself from the character. I know for sure that the weld will be in the trophy so other than to set its properties during equipping, I don’t need to care about the weld for unequipping. The essence behind unequipping is just destroying or unparenting the instances you don’t need.

When you have a set of guarantees, it’s easier to rationalise the logic of your systems. You don’t need to get rid of the armour weld if it’s parented to the armour, just destroy the armour model outright. As for returning the tool, that’s on you to figure out, but a tip there should be that you should identify what piece the player has equipped. This way, when you call your unequip logic, you can read off what piece was removed and accordingly give the player the corresponding tool.

1 Like

Well, I got the unweld model and add-back tool working. The only problem is that when i get back the tool it clones itself like 500 times. Do you know any easy functions that can handle too much cloning or do I have to manually make a clone check?

You could make a clone check but I feel it’s better suited that you address the root problem of why so many tool clones are being made in the first place. Your system should be able to guarantee that only one tool is created by default. Handle the root problem rather than the exceptional case.

1 Like

After looking at my code for a while… I still can’t find the problem. I made a modified script version of the helm tool, that just gets the clone of the helm tool when I activate the tool and it works perfectly. Then I made an else if statement that checks if the name of the player’s currently equipped item is different from the name of the item and if it is it will give the cloned item, and that works perfectly too. But when I try to do the same for the second item, the same problem occurs. Do clone objects fail frequently in Roblox studio? Or are clones just work differently when pairing them with multiple if statements?

Bumping this post, Dont mind me

bump again cause i have nothing to do