Tool on back wont remove

Hi,

I got this code from a youtube tutorial. It makes you equip a tool on your back when you are not holding it. It works good until i hold the tool, the tool on my back is not removed. Any toughts on this?

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local BackTools = ReplicatedStorage:WaitForChild("BackTools")



local Character = script.Parent

local UpperTorso = Character:FindFirstChild('UpperTorso') or Character:FindFirstChild('Torso')



local OldModel = nil



function Weld(weldMe, toThis)

	local weld = Instance.new("Weld")

	weld.Part0 = weldMe

	weld.Part1 = toThis

	weld.C0 = weldMe.CFrame:ToObjectSpace(toThis.CFrame)

	weld.Parent = toThis

end



Character.ChildRemoved:Connect(function(child)

	local Model = BackTools:FindFirstChild(child.Name)

	if child:IsA('Tool') and Model then

		if OldModel then

			OldModel:Destroy()

		end

		OldModel = Model:Clone()

		OldModel:SetPrimaryPartCFrame(UpperTorso.CFrame)

		OldModel.Parent = workspace

		Weld(OldModel.PrimaryPart, UpperTorso)

	end

end)

_r2_c2

1 Like

I’m confused, is the script trying to remove the back tool when you unequip the tool? If it is, you should change the event to Character.ChildAdded.
There should also be a function for Character.ChildRemoved to make the back tool appear on the back again (if there isn’t).

The script supposed to do: show item on back or hand… now it is on both.

I tried doing ChildAdded, but this will do basicly the same as ChildRemoved when i test it.

You technically can’t do both functions in the same event like this. So I suggest having both ChildAdded and ChildRemoved, each will do it’s own thing.

Added the following code:

Character.ChildAdded:Connect(function(child)
	if OldModel.Name == child.Name then
		OldModel:Destroy()
	end
end)

All is working now, thank you

2 Likes