Help with buy button

in my module , i wrote so that when the player equips the tool and the copy is in a folder which is parented to the player, it shouldn’t decrease the value but should go to player’s backpack.

1 Like

cod for that:

elseif player.Ownedtools:FindFirstChild(toolName) and player.Equipped.Value ~= toolName then
			print("h")
			for i,v in pairs(player.Backpack:GetChildren()) do
				print("A")
				if v:IsA("Tool") then
					v:Destroy()
					print("m")
				end
			end

			local gear = tool:Clone()
			print("f")
			gear.Parent = player.Backpack
			print("c")
			
			return "Equipped"
		elseif player.Ownedtools:FindFirstChild(toolName) and player.Equipped.Value == toolName then
			print("b")
			for i,v in pairs(player.Backpack:GetChildren()) do
				print("raid")
				if v:IsA("Tool") then
					v:Destroy()
					print("shadow")
				end
			end

			local gear = tool:Clone()
			print("legends")
			gear.Parent = player.Backpack
			return "Equipped"
		end
		
	else
		return "error"
	end
end
1 Like