Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Tool Is Gone ?

The problem is that sometimes when i equip and unequip then re-equip the tool the tool is gone, what i mean by that is that the tool is empty, no parts, no scripts like it had before

Script

local cl = game:ReplicatedStorage:WaitForChild('WoodenAxe')
local cl2 =  cl:Clone()

script.Parent.MouseButton1Click:connect(function()

if Bought.Value == true and Equiped == false and AnyEquiped.Value == false  then
			print('All Requirements Met')
			Type.Image = script.Parent.Parent.ImageLabel.Image
			cl2.Parent = player.Backpack	
			script.Parent.BackgroundColor3 = EquipColor2
			AnyEquiped.Value = true	
			Equiped = true
			script.Parent.Text = 'UnEquip'
			sound:Play()

elseif Bought.Value == true and Equiped == true then
		Humanoid:UnequipTools()
		wait(.1)
		Type.Image = NA.Value
		player.Backpack:findFirstChild("WoodenAxe"):remove()
		script.Parent.BackgroundColor3 = UnequipedColor2
		AnyEquiped.Value = false
		Equiped = false
		script.Parent.Text = 'Equip'
		sound:Play()

end	
	
	
end)

By the way this is just the portion of the script that has to do with the quesiton

1 comment

0

Normally I don't keep my tools in ReplicatedStorage. Wanna move it to ServerStorage and see what happens?

1 answer

✓ Accepted answer

Two problems. You need to use :Destroy() rather than :remove(); remove() takes up extra memory as it doesn't actually delete them from the game, just sets the parent to nil.

Also, you need to create a new clone each time. Your problem was that :remove() was setting all of the descendants' parents to nil, so when you set the clone's (the one that you only cloned once) parent, all of the children were gone.

To fix this, all you have to do is move cl2 to under the if statement, and use :Destroy() instead.

local cl = game:ReplicatedStorage:WaitForChild('WoodenAxe')

script.Parent.MouseButton1Click:connect(function()
	if Bought.Value == true and Equiped == false and AnyEquiped.Value == false  then
		local cl2 =  cl:Clone()
		print('All Requirements Met')
		Type.Image = script.Parent.Parent.ImageLabel.Image
		cl2.Parent = player.Backpack    
		script.Parent.BackgroundColor3 = EquipColor2
		AnyEquiped.Value = true 
		Equiped = true
		script.Parent.Text = 'UnEquip'
		sound:Play()

	elseif Bought.Value == true and Equiped == true then
		Humanoid:UnequipTools()
		wait(.1)
		Type.Image = NA.Value
		if player.Backpack:FindFirstChild("WoodenAxe") then
			player.Backpack:FindFirstChild("WoodenAxe"):Destroy() --// findFirstChild is deprecated, use FindFirstChild instead.
		end
		script.Parent.BackgroundColor3 = UnequipedColor2
		AnyEquiped.Value = false
		Equiped = false
		script.Parent.Text = 'Equip'
		sound:Play()
	end
end)

Hope this helped.

1 comment

0

Instead of spamming me with comments, submit a ticket to helpdesk.

This discussion is preserved as it was. New answers, comments, and votes are closed.